Skip to content

Conversation

@AndrewAsseily
Copy link
Contributor

@AndrewAsseily AndrewAsseily commented Dec 2, 2025

Issue #, if available: CLI-5136 & CLI-7572 & #2688

Description of changes:

Exposes modeled error members from AWS service exceptions to stdout in the configured output format (json/yaml/text/table/off), while maintaining the existing formatted error message on stderr.

Behavior:

Command: aws s3api get-object --bucket not-a-real-bucket-0000 --key file.txt out.txt

Before:

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

After (stdout):

{
    "Code": "NoSuchBucket",
    "Message": "The specified bucket does not exist",
    "BucketName": "not-a-real-bucket-0000"
}

After (stderr):

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

Configuration:

Users can opt out via:

  • Config: cli_error_format = LEGACY
  • Environment: AWS_CLI_ERROR_FORMAT=LEGACY

Additional Changes:

  • Added off as a valid output format option to suppress all output

Description of tests:

  • Unit and functional tests pass locally.

@AndrewAsseily AndrewAsseily changed the base branch from nyandrew/str-std-error to feature/str-std-error December 3, 2025 20:33
Comment on lines 1096 to 1098
except ClientError as e:
self._display_structured_error_for_exception(e, parsed_globals)
raise
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this block? Can the formatter raise a structured error that the actual API call wouldn't have?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pagination returns a lazy itertaor that formatting can consume and trigger a later page request. If that fails, catching around the formatter preserves the structured error for pagination-time failures

config_var_name='cli_error_format',
session=self.session,
),
ConstantProvider(value='STANDARD'),
Copy link
Member

Choose a reason for hiding this comment

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

Few things on the enum values:

  1. Left a comment elsewhere, but please start by documenting valid values in global_options.rst
  2. Add validation like we do for output for invalid values.
  3. Only STANDARD | LEGACY were never discussed as options, we should revisit with the team internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this comment until we discuss as a team.

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