Add ClientError getters for common attributes #3251
+36
−0
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.
Most errors returned from AWS APIs are captured in the ClientError class. When writing Python code that interacts with the AWS APIs, you frequently want to parse the specific error and/or error message.
The boto3 documentation describes how this can be accomplished by parsing the error code:
Looking at the botocore unit tests for exceptions there is a test case that checks if ClientError exceptions still work even if the Code or Message is not available.
That seems to indicate that this is an actual possibility which means the above suggested code could unexpectedly fail. To properly evaluate an error, the code should be something like this:
This is even more verbose than the boto3 documentation indicates, and might impact existing customers.
There are additional fields available that provide even more details of the error that can be useful. Extract from the boto3 documentation gives the following example.
It's great the information is available, but it's not easy to find the appropriate dictionary key names without looking at the documentation.
This pull requests adds getters (property) to the ClientError class to extract these values. The added benefit is that IDE's will be able to autocomplete the getters and inline documentation. It will also lead to less verbose code for users of the library.
Here's an example of how it improves readability for the users of the library: