Skip to content

refactor(parser): Improve error message when parsing models and envelopes #3587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2024
Merged

refactor(parser): Improve error message when parsing models and envelopes #3587

merged 4 commits into from
Jan 5, 2024

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #3580

Summary

Changes

This pull request enhances the error messaging in response to an AttributeError when parsing Models and Envelopes. The improved error message now provides more explicit details, making it easier to identify and address the root cause of the issue.

Before

[ERROR] InvalidEnvelopeError: Envelope must implement BaseEnvelope, envelope=<class 'aws_lambda_powertools.utilities.parser.envelopes.kinesis.KinesisDataStreamEnvelope'>

[ERROR] InvalidEnvelopeError: Envelope must implement BaseEnvelope, envelope=<class 'aws_lambda_powertools.utilities.parser.envelopes.kinesis.KinesisDataStreamEnvelope'>
Traceback (most recent call last):
  File "/var/task/aws_lambda_powertools/middleware_factory/factory.py", line 135, in wrapper
    response = middleware()
  File "/var/task/aws_lambda_powertools/utilities/parser/parser.py", line 98, in event_parser
    parsed_event = parse(event=event, model=model, envelope=envelope)
  File "/var/task/aws_lambda_powertools/utilities/parser/parser.py", line 175, in parse
    raise InvalidEnvelopeError(f"Envelope must implement BaseEnvelope, envelope={envelope}")

After

[ERROR] InvalidEnvelopeError: Error: 'list' object has no attribute 'test'. Please ensure that both the Input model and Envelope inherit from BaseModel,
And your payload adheres to the specified Input model structure.
Envelope=<class 'aws_lambda_powertools.utilities.parser.envelopes.kinesis.KinesisDataStreamEnvelope'>
Model=<class 'app.SuggestionPayload'>

[ERROR] InvalidEnvelopeError: Error: 'list' object has no attribute 'test'. Please ensure that both the Input model and Envelope inherit from BaseModel,
And your payload adheres to the specified Input model structure.
Envelope=<class 'aws_lambda_powertools.utilities.parser.envelopes.kinesis.KinesisDataStreamEnvelope'> 
Model=<class 'app.SuggestionPayload'>
Traceback (most recent call last):
  File "/var/task/aws_lambda_powertools/middleware_factory/factory.py", line 135, in wrapper
    response = middleware()
  File "/var/task/aws_lambda_powertools/utilities/parser/parser.py", line 98, in event_parser
    parsed_event = parse(event=event, model=model, envelope=envelope)
  File "/var/task/aws_lambda_powertools/utilities/parser/parser.py", line 175, in parse

User experience

Please share what the user experience looks like before and after this change

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@leandrodamascena leandrodamascena requested a review from a team January 3, 2024 18:11
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 3, 2024
@leandrodamascena leandrodamascena linked an issue Jan 3, 2024 that may be closed by this pull request
@codecov-commenter
Copy link

codecov-commenter commented Jan 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f6a3ac1) 95.78% compared to head (d61042b) 95.78%.
Report is 5 commits behind head on develop.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3587   +/-   ##
========================================
  Coverage    95.78%   95.78%           
========================================
  Files          210      210           
  Lines         9683     9683           
  Branches      1774     1774           
========================================
  Hits          9275     9275           
  Misses         294      294           
  Partials       114      114           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

rubenfonseca
rubenfonseca previously approved these changes Jan 4, 2024
Copy link
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some NP, otherwise good to go!

@leandrodamascena leandrodamascena added the parser Parser (Pydantic) utility label Jan 5, 2024
Copy link

sonarqubecloud bot commented Jan 5, 2024

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@leandrodamascena leandrodamascena merged commit aacb37d into aws-powertools:develop Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Parser (Pydantic) utility size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Improve error message when parser fails
3 participants