{"record":{"id":"5096a20861e21ac7","repo":"reacherhq/check-if-email-exists","slug":"no-messages-in-the-event","errorCode":null,"errorMessage":"No messages in the event","messagePattern":"No messages in the event","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sqs/src/main.rs","lineNumber":94,"sourceCode":"\t\t// show up in a confusing manner in CloudWatch logs.\n\t\t.with_ansi(false)\n\t\t// disabling time is handy because CloudWatch will add the ingestion time.\n\t\t.without_time()\n\t\t// remove the name of the function from every log entry\n\t\t.with_target(false)\n\t\t.init();\n\tinfo!(version=?CARGO_PKG_VERSION, \"Starting Reacher SQS lambda.\");\n\n\trun_and_wait_chromedriver().await?;\n\n\tlambda_runtime::run(service_fn(handler)).await?;\n\tOk(())\n}\n\nasync fn handler(event: LambdaEvent<SQSPayload>) -> Result<CheckEmailOutput, Error> {\n\tlet (request, _context) = event.into_parts();\n\t// Since we're only fetching a single message, we can safely unwrap here.\n\tlet message = request.records.first().expect(\"No messages in the event\");\n\tlet task: CheckEmailPartialTask = serde_json::from_str(&message.body)?;\n\tinfo!(email = ?task.input.to_email, \"Processing task\");\n\n\tlet backend_config = Arc::new(load_config().await?);\n\tdebug!(\"{:#?}\", backend_config);\n\n\tlet task = &task.into_check_email_task(backend_config.clone());\n\n\tlet worker_output = check_email_and_send_result(task).await;\n\tmatch worker_output.as_ref() {\n\t\tOk(output) => {\n\t\t\tinfo!(email = ?output.input, is_reachable = ?output.is_reachable, \"Task completed\");\n\t\t}\n\t\tErr(e) => {\n\t\t\tinfo!(email = ?task.input.to_email, err = ?e, \"Task failed\");\n\t\t}\n\t}\n","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/reacherhq/check-if-email-exists/blob/81da93e8a419f601c05e1bcf4a197d25eb0e349d/sqs/src/main.rs#L76-L112","documentation":"The Lambda SQS handler is designed to receive exactly one message per event and takes the first record with expect(). If the SQS event arrives with zero records, the panic \"No messages in the event\" aborts the Lambda invocation. It guards an assumption about the event shape that batch sizes or test invocations can violate.","triggerScenarios":"An SQS event with an empty Records array is delivered — e.g. a direct Lambda test invocation with an empty event body, or an SQS/Lambda integration delivering a zero-record event (possible with certain batch configurations or malformed test payloads).","commonSituations":"Developers testing the Lambda from the AWS console with `{}` or an empty sample event; pipeline integrations (EventBridge pipes, S3→SQS setups) invoking with unexpected payloads; races where a batch is drained before delivery.","solutions":["Return an error instead of panicking when records are empty, letting the Lambda runtime report it cleanly.","Ensure test invocations use a proper SQS event sample containing one Records entry.","Verify the function's event source mapping is attached to the intended SQS queue.","Handle the single-message assumption explicitly with records.first().ok_or(...)."],"exampleFix":"// before\nlet message = request.records.first().expect(\"No messages in the event\");\n// after\nlet message = request.records.first().ok_or_else(|| anyhow::anyhow!(\"No messages in the event\"))?;","handlingStrategy":"try-catch","validationCode":"if event.records.is_empty() {\n    return Err(anyhow::anyhow!(\"SQS event contained no records\"));\n}","typeGuard":"fn has_records(event: &SQSPayload) -> bool {\n    !event.records.is_empty()\n}","tryCatchPattern":"// in the handler, replace expect with graceful error return\nlet message = request.records.first().ok_or_else(|| {\n    error!(\"SQS event had zero records\");\n    anyhow::anyhow!(\"No messages in the event\")\n})?;","preventionTips":["Use realistic SQS event samples (with a non-empty Records array) when testing in the Lambda console.","Verify the SQS event source mapping targets the correct queue.","Prefer ok_or(...)? over expect()/unwrap() in Lambda handlers so panics do not hit the runtime."],"tags":["aws","lambda","sqs","panic","empty-input"],"backgroundTag":"empty-required-field","analyzedSha":"81da93e8a419f601c05e1bcf4a197d25eb0e349d","analyzedAt":"2026-09-11T10:06:14.663Z","contentChangedAt":"2026-09-11T10:06:14.663Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}