-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Structured Error Output #9890
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
base: feature/str-std-error
Are you sure you want to change the base?
Structured Error Output #9890
Conversation
This reverts commit 1afe452.
| { | ||
| "type": "feature", | ||
| "category": "Output", | ||
| "description": "AWS service errors containing modeled fields beyond Code and Message now write structured output to stdout in the configured output format. Set cli_error_format=LEGACY to disable or use --output off to suppress stdout." | ||
| } |
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.
--output off is substantial, please add its own entry in a separate file.
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.
Don't need to see changes, but in hindsight I'd rather have done --output off in a separate PR, these features aren't dependent on one another technically.
|
|
||
| * yaml-stream | ||
|
|
||
| * off |
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.
While we're here, can you catch up the section in the API reference too?
aws-cli/awscli/topics/config-vars.rst
Lines 92 to 96 in 33dbfd2
| The valid values of the ``output`` configuration variable are: | |
| * json | |
| * table | |
| * text |
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.
Also add new information there on the new error format setting.
| @@ -0,0 +1,94 @@ | |||
| # Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved. | |||
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.
nit: Throughout, either drop years, or use the short version:
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
| except ClientError as e: | ||
| self._display_structured_error_for_exception(e, parsed_globals) | ||
| raise |
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.
Why do we need this block? Can the formatter raise a structured error that the actual API call wouldn't have?
| config_var_name='cli_error_format', | ||
| session=self.session, | ||
| ), | ||
| ConstantProvider(value='STANDARD'), |
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.
Few things on the enum values:
- Left a comment elsewhere, but please start by documenting valid values in
global_options.rst - Add validation like we do for
outputfor invalid values. - Only
STANDARD | LEGACYwere never discussed as options, we should revisit with the team internally.
| LOG = logging.getLogger('awscli.structured_error') | ||
|
|
||
|
|
||
| class StructuredErrorHandler: |
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.
Can this be handled through the existing ClientErrorHandler? That already has an overridable method with access to stdout/stderr.
We'd need less new plumbing in the driver, and we already should have confidence that it is catching ClientError instances.
I also wonder if that'll help apply more of this to custom commands.
| try: | ||
| formatter = get_formatter(output, parsed_globals) | ||
|
|
||
| with self._output_stream_factory.get_output_stream() as stream: |
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.
- In the last internal review of the design doc, we weren't keen anymore on writing these to stdout. Users checking for any output and assuming that means the command was successful may be broken.
- I definitely don't think we should feed errors into the pager. It's odd to need to
qto see the original message. Though they can contain lists, there is no mechanism for pagination.
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.txtBefore:
An error occurred (NoSuchBucket) when calling the GetObject operation: The specified bucket does not existAfter (stdout):
After (stderr):
An error occurred (NoSuchBucket) when calling the GetObject operation: The specified bucket does not existConfiguration:
Users can opt out via:
cli_error_format = LEGACYAWS_CLI_ERROR_FORMAT=LEGACYAdditional Changes:
offas a valid output format option to suppress all outputDescription of tests: