Repository: awslabs/aws-lambda-rust-runtime (language: rust)

Issue:
Error of handler is no longer printed
I noticed that starting with version `0.11.0` an error from a handler is no longer printed and not sent to CloudWatch logs.

The PR #845 states:
> [...] Using the top-level run function should result in functionally (almost) equivalent code (except for some logging statements).

Reading this comment I guess the change in behavior is expected.
In case of an error, debugging the Lambda becomes way harder since there is no log message why and even that the Lambda failed.

Is there already a solution how to get the old behavior (error being logged) back?

## How to reproduce

### Example code

Example code to reproduce the issue
```rust
use lambda_runtime::{run, service_fn, LambdaEvent};
use serde::Deserialize;
use tracing::info;

#[derive(Deserialize)]
struct Request {}

#[tokio::main]
async fn main() -> Result<(), lambda_runtime::Error> {
    lambda_runtime::tracing::init_default_subscriber();

    run(service_fn(handler)).await
}

async fn handler(_event: LambdaEvent<Request>) -> anyhow::Result<()> {
    info!("hi from handler");

    Err(anyhow::Error::msg("This log message is printed nowhere"))
}
```

### Version `>=0.11.0`

If I run it with (for example) version `0.11.2` and the commands `cargo lambda watch` and `cargo lambda invoke --data-ascii "{}"` gives me the output:

```
INFO Lambda runtime invoke{requestId="10c0a11b-602d-418a-aff1-8931c10fd234" xrayTraceId="Root=1-665f22b0-9ba7379721f58c9124e882ff;Parent=56d52e45d9740162;Sampled=1"}: hi from handler
```

### Version `0.10.0`

If I run it with version `0.10.0` I see the error:
```
INFO Lambda runtime invoke{requestId="aa50b9cc-4af9-44c4-a91b-f1d89d398e1b" xrayTraceId="Root=1-665f2357-b44fa3fc478ba6def2d07857;Parent=4a2a30e259041ad1;Sampled=1"}: hi from handler
ERROR Lambda runtime invoke{requestId="aa50b9cc-4af9-44c4-a91b-f1d89d398e1b" xrayTraceId="Root=1-665f2357-b44fa3fc478ba6def2d07857;Parent=4a2a30e259041ad1;Sampled=1"}: This log message is printed nowhere
```






Discussion / hints:

Fix patch:
diff --git a/lambda-runtime/src/layers/panic.rs b/lambda-runtime/src/layers/panic.rs
index 26ceeecc..6600b743 100644
--- a/lambda-runtime/src/layers/panic.rs
+++ b/lambda-runtime/src/layers/panic.rs
@@ -58,9 +58,9 @@ where
                 let fut = AssertUnwindSafe(task).catch_unwind();
                 CatchPanicFuture::Future(fut, PhantomData)
             }
-            Err(err) => {
-                error!(error = ?err, "user handler panicked");
-                CatchPanicFuture::Error(err)
+            Err(error) => {
+                error!(?error, "user handler panicked");
+                CatchPanicFuture::Error(error)
             }
         }
     }
@@ -85,15 +85,19 @@ where
         match self.project() {
             CatchPanicFutureProj::Future(fut, _) => match fut.poll(cx) {
                 Poll::Ready(ready) => match ready {
-                    Ok(inner_result) => Poll::Ready(inner_result.map_err(|err| err.into())),
-                    Err(err) => {
-                        error!(error = ?err, "user handler panicked");
-                        Poll::Ready(Err(Self::build_panic_diagnostic(&err)))
+                    Ok(Ok(success)) => Poll::Ready(Ok(success)),
+                    Ok(Err(error)) => {
+                        error!("{error:?}");
+                        Poll::Ready(Err(error.into()))
+                    }
+                    Err(error) => {
+                        error!(?error, "user handler panicked");
+                        Poll::Ready(Err(Self::build_panic_diagnostic(&error)))
                     }
                 },
                 Poll::Pending => Poll::Pending,
             },
-            CatchPanicFutureProj::Error(err) => Poll::Ready(Err(Self::build_panic_diagnostic(err))),
+            CatchPanicFutureProj::Error(error) => Poll::Ready(Err(Self::build_panic_diagnostic(error))),
         }
     }
 }


Test patch: