Skip to content

fix(jmespath): raise InvalidEnvelopeExpressionError for all JMESPath parse errors - #8943

Open
0x5t4l1n wants to merge 1 commit into
aws-powertools:developfrom
0x5t4l1n:fix/validation-envelope-parse-errors
Open

0x5t4l1n wants to merge 1 commit into
aws-powertools:developfrom
0x5t4l1n:fix/validation-envelope-parse-errors

Conversation

@0x5t4l1n

@0x5t4l1n 0x5t4l1n commented Dec 2, 2026 •

Copy link
Copy Markdown

Summary

validate() and @validator document InvalidEnvelopeExpressionError for an invalid envelope, but jmespath_utils.query() only converted LexerError. Other syntax errors (IncompleteExpressionError, ArityError, ParseError) escaped as raw jmespath exceptions, so except InvalidEnvelopeExpressionError missed them.

query() now catches jmespath.exceptions.ParseError, the parent of LexerError and of those siblings. LexerError behaviour is unchanged and other exceptions are untouched.

closes #8918

Verification

AI-assisted (Claude Code). I ran everything myself on Python 3.13:

  • Added test_validate_malformed_envelope_raises_invalid_envelope_expression_error through the public validate() API, using the four envelopes from the issue. Without the fix 3 of 4 cases fail (the unclosed quote case already passed); with the fix all pass.
  • pytest tests/functional/validator tests/unit/jmespath_util: 34 passed.
  • ruff format --check, ruff check and mypy on the changed code are clean.
  • I did not run the full make pr or the Python 3.10/3.11/3.12/3.14 matrix locally; CI covers those.
  • No AWS service integration involved.

User experience

Before: except InvalidEnvelopeExpressionError missed some malformed envelopes, which surfaced as raw jmespath exceptions. After: every envelope syntax error raises InvalidEnvelopeExpressionError, as documented.


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.

…parse errors

query() only converted LexerError. Other syntax errors (IncompleteExpressionError,
ArityError, ParseError) escaped as raw jmespath exceptions, so validate() and
@validator callers catching InvalidEnvelopeExpressionError missed them.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@0x5t4l1n
0x5t4l1n requested a review from a team as a code owner December 2, 2026 15:15
@boring-cyborg

boring-cyborg Bot commented Dec 2, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@boring-cyborg boring-cyborg Bot added jmespath JMESPath Functions utility tests labels Dec 2, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 2, 2026
@sonarqubecloud

sonarqubecloud Bot commented Dec 2, 2026

Copy link
Copy Markdown

@0x5t4l1n

0x5t4l1n commented Dec 2, 2026

Copy link
Copy Markdown
Author

I've added the missing acknowledgment text and a User experience section to the PR description so the Acknowledgment Check can pass. No code changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jmespath JMESPath Functions utility size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: validate() raises raw jmespath ParseError instead of InvalidEnvelopeExpressionError for most malformed envelopes

1 participant