-
Notifications
You must be signed in to change notification settings - Fork 429
fix(idempotency): Log nested exception message #1813
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
leandrodamascena
merged 3 commits into
aws-powertools:develop
from
mploski:fix/idempotency-print-nested-exception
Jan 9, 2023
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @mploski! This is a huge improvement indeed. I remember the first time I needed to use the idempotency utility, I got an error due to permissions and spent a lot of time figuring out the reason for the "Failed to save record in progress to idempotency store" message. Creating a specific class to capture and return detailed errors makes life and adoption easier!!
I was wondering if we really need to instantiate the parent Exception class or if we could change this code to directly return the error message and make the code more clean. But it's just an idea to think about, I'm not sure and would just like to hear your side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @leandrodamascena , thx for the feedback!
I like your proposal and I refactored my code to follow your suggestion i.e to modify how exception is printed in str dunder method. This approach also has additional benefit that we keep initial attributes ( in args list) in object itself so we can easily see how exception object was initialized during debugging if needed.
As for the super class calling. In theory it is suggested to call it as explained in Python Cookbook book: https://books.google.pl/books?id=f7wGeA71_eUC&pg=PA579&dq=To+illustrate+the+use+of+.args,+consider+this+interactive+session+with+the+built-in+RuntimeError+exception,+and+notice+how+any+number+of+arguments+can+be+used+with+the+raise+statement:&hl=en&sa=X&ved=2ahUKEwinm_Dy0bX8AhWMposKHQNHB3oQ6AF6BAgBEAI#v=onepage&q=To%20illustrate%20the%20use%20of%20.args%2C%20consider%20this%20interactive%20session%20with%20the%20built-in%20RuntimeError%20exception%2C%20and%20notice%20how%20any%20number%20of%20arguments%20can%20be%20used%20with%20the%20raise%20statement%3A&f=false.
I dove deep more to see what happens when we call Exception init method. It seems this behavior changed somewhere in newer python 3 releases and args list initialization was moved to new dunder method so all needed stuff is initialized either way even without calling superclass init method ( as oppose to python 2.x and 3.0 for example) . So I think we can safely omit it.
here is a c code for new method in exception class in python 3 main branch: https://github.com/python/cpython/blob/3.7/Objects/exceptions.c#L47 - you can see that we copy args to instance attribute
and in Python 3.0:
https://github.com/python/cpython/blob/v3.0/Objects/exceptions.c#L49 - you can see that this action is done only in init not in new
Can I ask you to review it once again? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @mploski! Thank you very much for your feedback and all the links provided, it was very helpful to understand more deeply how the exception is handled and it arguments.
From my side everything is ok and we are ready to merge!