Repository navigation
fix(parser): let SnsSqsEnvelope safeParse propagate schema errors - #5846
Merged
dreamorosi merged 1 commit intoOct 26, 2026
Merged
dreamorosi merged 1 commit into
dreamorosi merged 1 commit into
Conversation
SnsSqsEnvelope.safeParse caught errors thrown by the user's schema and turned them into a custom Zod issue holding only the message, so a bug in the schema was reported as invalid input and the original error was lost. Every other envelope lets the error propagate, in line with Zod's guidance that transforms should never throw. Remove the try/catch around the SNS notification and user schema parsing, and keep the one around JSON.parse so a malformed record body still returns a failed result with a custom issue. Closes aws-powertools#5829
dreamorosi
approved these changes
Oct 26, 2026
dreamorosi
enabled auto-merge (squash)
October 26, 2026 08:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SnsSqsEnvelope.safeParsecaught errors thrown by the user's schema and turned them into acustomZod issue holding only the message. A bug in the schema was reported as invalid input, and the original error was lost. Every other envelope'ssafeParselets the error propagate, in line with Zod's guidance that transforms should never throw. This makesSnsSqsEnvelopeconsistent with them.Changes
try/catcharoundSnsSqsNotificationSchema.safeParseand the user'sschema.safeParseinSnsSqsEnvelope.safeParse(packages/parser/src/envelopes/sns-sqs.ts), so an error thrown by the schema propagates unchanged.try/catcharoundJSON.parse(record.body), so a malformed record body still returns{ success: false }with acustomissue atRecords[i].body. The existing tests for that case are unchanged and pass.customissue with one that assertssafeParsethrows the original error. It fails againstmain.SnsSqsEnvelope.parseis unchanged, since it already wraps the thrown error in aParseErrorwith the original error ascause.Issue number: closes #5829
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.