Repository navigation
fix(parser): wrap envelope parse failures in ParseError - #5758
Merged
svozza merged 3 commits intoOct 10, 2026
Merged
Conversation
SnsEnvelope, CloudWatchEnvelope, DynamoDBStreamEnvelope and KafkaEnvelope let the envelope-level ZodError escape from parse(), so the errorHandler option was skipped. KafkaEnvelope also threw raw errors for records that failed the user schema and for an unknown eventSource. Closes aws-powertools#5742
svozza
reviewed
Oct 2, 2026
svozza
requested changes
Oct 5, 2026
Contributor
|
Do you need any help with this PR @Provokke. If you don't have capacity, I'm happy to complete it, you will still get credited in the git history. |
Contributor
Author
|
@svozza Will make fix now! |
…arse-error # Conflicts: # packages/parser/tests/unit/parser.middy.test.ts
Add parseOrThrow to envelope.ts and use it for the envelope and record parses in the array envelopes, instead of repeating the same try/catch in each one. Messages and issue paths are unchanged.
Contributor
Author
|
@svozza Done, ready for another look when you have a moment.
The parser suite passes locally with 100% coverage, and |
svozza
approved these changes
Oct 10, 2026
Contributor
|
Nice! LGTM. |
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
Changes
SnsEnvelope,CloudWatchEnvelope,DynamoDBStreamEnvelopeandKafkaEnvelopelet a rawZodErrorescape fromparse().invokeErrorHandleronly handlesParseError, so theerrorHandleroption was skipped and the error was rethrown.ParseErrorwith theZodErrorascause. The messages match the ones each envelope'ssafeParse()already uses (Failed to parse SNS envelope, and so on).KafkaEnvelope.parse(), putextractEventSource()and the MSK/self-managed schema parse inside the sametry, so an unknowneventSourcebecomes aParseErrortoo.Failed to parse Kafka record at index 0 of mytopic-0), and the issue paths are prefixed with['records', topicKey, index, 'value']throughprefixIssuePaths, the same way the other array envelopes do it. A transform that throws keeps its original error ascause, matching fix(parser): keep transform errors as the ParseError cause #5745.I left
KafkaEnvelope.safeParse()alone. It prefixes record issues with['records', topicKey], without the record index orvalue. I can align it here or in a follow-up if you'd like.Tests: the snippet from the issue passes (6/6). I added
parse()tests for an invalid envelope in each of the four envelopes, for a Kafka record that fails the schema (message and path), for a throwing transform in Kafka, and for an unknown KafkaeventSource. There is also a middleware test that checkserrorHandleris called whenSnsEnvelopefails. Without the source change, all 8 new tests fail. The parser unit suite passes (306 tests) with the 100% coverage gate, andbuild:tests,test:unit:typesand Biome on the changed files are clean.Issue number: closes #5742
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.