Skip to content

Filter unmodeled fields from error output#10142

Open
AndrewAsseily wants to merge 5 commits intoaws:v2from
AndrewAsseily:error-field-tagging
Open

Filter unmodeled fields from error output#10142
AndrewAsseily wants to merge 5 commits intoaws:v2from
AndrewAsseily:error-field-tagging

Conversation

@AndrewAsseily
Copy link
Contributor

@AndrewAsseily AndrewAsseily commented Mar 17, 2026

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:

(.venv)  aws-cli % aws s3api get-object --bucket not-a-real-bucket-0000 --key file.txt out.txt

aws: [ERROR]: An error occurred (NoSuchBucket) when calling the GetObject operation: The specified bucket does not exist

Additional error details:
BucketName: not-a-real-bucket-0000

After:

(.venv)  aws-cli % aws s3api get-object --bucket not-a-real-bucket-0000 --key file.txt out.txt                          

aws: [ERROR]: An error occurred (NoSuchBucket) when calling the GetObject operation: The specified bucket does not exist

Modeled: https://github.com/aws/aws-cli/blob/v2/awscli/botocore/data/lambda/2015-03-31/service-2.json#L7930

(.venv) aws-cli % aws lambda get-function --function-name nonexistent-function-12345

aws: [ERROR]: An error occurred (ResourceNotFoundException) when calling the GetFunction operation: Function not found: arn:aws:lambda:us-west-2:<redacted-for-this-PR>:function:nonexistent-function-12345

Additional error details:
Type: User

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@AndrewAsseily AndrewAsseily requested a review from ashovlin March 18, 2026 15:00
@AndrewAsseily AndrewAsseily marked this pull request as ready for review March 18, 2026 15:00
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
Copy link
Member

Choose a reason for hiding this comment

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

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?

Comment on lines +296 to +298
error_info = error_response['Error']
modeled_fields = getattr(exception, 'modeled_fields', None)
error_info['_modeled_fields'] = modeled_fields
Copy link
Member

Choose a reason for hiding this comment

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

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants