From 395e2ff8548f67a41e94493a317d022978e46c83 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 4 May 2021 16:42:58 -0700 Subject: [PATCH] fix: don't panic on missing headers under SAM SAM is missing these, making local testing impossible without this change. --- lambda-runtime/src/types.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lambda-runtime/src/types.rs b/lambda-runtime/src/types.rs index c8579250..160ef9bb 100644 --- a/lambda-runtime/src/types.rs +++ b/lambda-runtime/src/types.rs @@ -128,14 +128,18 @@ impl TryFrom for Context { .to_str()? .parse() .expect("Missing deadline"), - invoked_function_arn: headers["lambda-runtime-invoked-function-arn"] - .to_str() - .expect("Missing arn; this is a bug") - .to_owned(), - xray_trace_id: headers["lambda-runtime-trace-id"] - .to_str() - .expect("Invalid XRayTraceID sent by Lambda; this is a bug") - .to_owned(), + invoked_function_arn: headers + .get("lambda-runtime-invoked-function-arn") + .map(|h| h.to_str().expect("Invalid arn; this is a bug").to_owned()) + .unwrap_or_default(), + xray_trace_id: headers + .get("lambda-runtime-trace-id") + .map(|h| { + h.to_str() + .expect("Invalid XRayTraceID sent by Lambda; this is a bug") + .to_owned() + }) + .unwrap_or_default(), ..Default::default() }; Ok(ctx)