Skip to content

Commit a18ffc3

Browse files
authored
wstd::http_server: don't panic after setting responder.fail (#117)
passing the error out to the host via responder.fail is all thats needed here - the host is responsible for reporting that error, so theres no need for the guest to panic afterwards. So, Responder::fail no longer needs a return value, and the macro no longer needs to unwrap it
1 parent 07ccea6 commit a18ffc3

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

macro/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ pub fn attr_macro_http_server(_attr: TokenStream, item: TokenStream) -> TokenStr
138138
match ::wstd::http::request::try_from_incoming(request) {
139139
Ok(request) => match __run(request) #run_await {
140140
Ok(response) => { responder.respond(response).await.unwrap() },
141-
Err(err) => responder.fail(err).unwrap(),
141+
Err(err) => responder.fail(err),
142142
}
143-
Err(err) => responder.fail(err).unwrap(),
143+
Err(err) => responder.fail(err),
144144
}
145145
})
146146
}

src/http/server.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ impl Responder {
7777

7878
/// This is used by the `http_server` macro.
7979
#[doc(hidden)]
80-
pub fn fail(self, err: Error) -> Result<(), Error> {
80+
pub fn fail(self, err: Error) {
8181
let e = match err.downcast_ref::<ErrorCode>() {
8282
Some(e) => e.clone(),
8383
None => ErrorCode::InternalError(Some(format!("{err:?}"))),
8484
};
8585
ResponseOutparam::set(self.outparam, Err(e));
86-
Err(err)
8786
}
8887
}

0 commit comments

Comments
 (0)