From 904f536b18ac0476c4ad045e6983209727d9fe6a Mon Sep 17 00:00:00 2001 From: Ryan Levick Date: Wed, 5 Apr 2023 18:07:58 +0200 Subject: [PATCH] Show error source list when printing handler error Signed-off-by: Ryan Levick --- sdk/rust/macro/src/lib.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sdk/rust/macro/src/lib.rs b/sdk/rust/macro/src/lib.rs index e7c11cbde1..d28b4966be 100644 --- a/sdk/rust/macro/src/lib.rs +++ b/sdk/rust/macro/src/lib.rs @@ -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,