Skip to content

Commit

Permalink
Merge pull request #1358 from fermyon/error-chain
Browse files Browse the repository at this point in the history
Show error source list when printing handler error
  • Loading branch information
rylev authored Apr 6, 2023
2 parents 892ecb6 + 904f536 commit fd6069c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions sdk/rust/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ pub fn http_component(_attr: TokenStream, item: TokenStream) -> TokenStream {

match #func_name(req.try_into().expect("cannot convert from Spin HTTP request")) {
Ok(resp) => resp.try_into().expect("cannot convert to Spin HTTP response"),
Err(e) => {
let body = e.to_string();
Err(error) => {
let body = error.to_string();
eprintln!("Handler returned an error: {}", body);
let mut error: &(dyn std::error::Error + 'static) = &*error;
while let Some(source) = error.source() {
eprintln!(" caused by: {}", source);
error = source;
}
spin_http::Response {
status: 500,
headers: None,
Expand Down

0 comments on commit fd6069c

Please # to comment.