awslabs / aws-lambda-rust-runtime

A Rust runtime for AWS Lambda
Apache License 2.0
3.29k stars 335 forks source link

Improved error messages about payload deserialization #905

Closed rimutaka closed 1 month ago

rimutaka commented 1 month ago

This PR makes errors about payload deserialization into a concrete event type more informative.

For example, my lambda had LambdaEvent<ApiGatewayProxyRequest> and was failing with the following error message:

ERROR lambda_runtime::layers::api_response: building error response for Lambda Runtime API error=DeserializeError { inner: Error { path: Path { segments: [] }, original: Error("missing field `httpMethod`", line: 1, column: 49) } }

That error message makes perfect sense to the developer of the runtime. A runtime user is likely to be stumped.

The problem is a mismatch between the payload and the target type, but the error says building error response for Lambda Runtime API. What does that mean?

I had to look up the runtime source to understand what's going on.

The proposed message is makes it clearer that the error happened before the handler was called, relates to the deserialization and suggests where to find more info (TRACE):

ERROR lambda_runtime::layers::api_response: Request payload deserialization into LambdaEvent<T> failed. The handler will not be called. Log at TRACE level to see the payload. error=DeserializeError { inner: Error { path: Path { segments: [] }, original: Error("missing field `httpMethod`", line: 1, column: 49) } }

I also added a note about logging with TRACE to see the raw payload. It is a very useful feature that is worth mentioning. I accidentally stumbled across it while working on this PR.

Looks like the runtime uses TRACE and not DEBUG.

Changes made

🔏 By submitting this pull request