Filter unmodeled fields from error output#10142
Filter unmodeled fields from error output#10142AndrewAsseily wants to merge 5 commits intoaws:v2from
Conversation
…g, return empty dict for unknown modeled fields
| error_class = self.exceptions.from_code(error_code) | ||
| raise error_class(parsed_response, operation_name) | ||
| error = error_class(parsed_response, operation_name) | ||
| error.modeled_fields = modeled_fields |
There was a problem hiding this comment.
Can we do this through either the constructor or a property that defaults to none so we don't need to be as defensive with the getattr(exception, 'modeled_fields', None) later?
| error_info = error_response['Error'] | ||
| modeled_fields = getattr(exception, 'modeled_fields', None) | ||
| error_info['_modeled_fields'] = modeled_fields |
There was a problem hiding this comment.
We're extracting .modeled_fields from the exception, copying that into error_info['_modeled_fields], then later using that to delete keys from error_info?
That was tough to follow. Can _extract_error_response, when it's building error_dict, ignore the unmodeled keys initially?
I think that'll be simpler and easier to follow. _extract_error_response remains responsible for extracting the info from the exception we care about, rather than that "leaking" that responsibility into a "display" method.
Description of changes: The CLI's "Additional error details" section previously displayed all fields from the error response, including fields not defined in the service model. This change filters the output to only show fields that are explicitly defined in the service's error shape model.
Non-modeled: https://github.com/aws/aws-cli/blob/v2/awscli/botocore/data/s3/2006-03-01/service-2.json#L8516
Before:
After:
Modeled: https://github.com/aws/aws-cli/blob/v2/awscli/botocore/data/lambda/2015-03-31/service-2.json#L7930
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.