-
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
Structured Error Output #9890
Conversation
This reverts commit 1afe452.
This fix addresses failures encountered on some systems when running the startlivetail unit tests through the AWS CLI test runner script at `scripts/ci/run-tests`. According to prompt toolkit documentation: > During the creation of a prompt_toolkit Application, we can specify > what input and output device to be used. By default, these are output > objects that correspond with sys.stdin and sys.stdout. In unit tests > however, we want to replace these. > - For the input, we want a “pipe input”. This is an input device, > in which we can programmatically send some input. It can be created > with create_pipe_input(), and that return either a PosixPipeInput or a > Win32PipeInput depending on the platform. Reference: https://python-prompt-toolkit.readthedocs.io/en/stable/pages/advanced_topics/unit_testing.html This change adds an optional `app_input`` parameter so that the test can be run with `create_pipe_input()` to replace the input for unit testing.
Co-authored-by: Sowjanya Pandruju <[email protected]>
…into feature/str-std-error
…aws-cli into nyandrew/structured-error
…into feature/str-std-error
…ing the expected error message format to include the new An error occurred (ParamValidation): prefix.
…test_suppresses_complex_response, test_suppresses_empty_response) into a single test_suppresses_response test
…mand.py by updating the expected error message to include the new An error occurred (ParamValidation): prefix.
| stream.write('\nAdditional error details:\n') | ||
| for key, value in additional_fields.items(): | ||
| if self._is_simple_value(value): | ||
| stream.write(f'{key}: {value}\n') |
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.
Wondering if we should indent these under the "Additional error details header"
Something like:
aws: [ERROR]: An error occurred (NoSuchBucket) when calling the ListObjects operation: The specified bucket does not exist
Additional error details:
BucketName: nonexistant-bucket
I'm leaning towards yes, but not a strong opinion. Can maybe check with the internal team quickly.
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.
Good call, I debated this earlier on and went against indentation because I thought it didn't look as clean when there's only a single additional field. But I agree it's worth revisiting. I'll bring it up with the team internally and see what they think.
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.
I'm okay either way, and it'd be safe to change post-launch too.
11c772c
into
aws:feature/str-std-error
Issue
CLI-5136 & CLI-7572 & #2688
Description of changes
Adds structured error formatting support for both AWS service errors and CLI exceptions. Users can now view errors in JSON, YAML, legacy, enhanced, text, or table formats using
--cli-error-format.For service errors (ClientError): Exposes modeled error members that AWS services return. For example, DynamoDB's
TransactionCanceledExceptionincludesCancellationReasonswith details about which operations failed.For CLI exceptions: Provides structured output for errors like
NoCredentialsError,NoRegionError, andParamValidationError.New
--output offformat: Suppresses all stdout output while preserving stderrExamples
DynamoDB TransactionCanceledException
Command:
Enhanced format (default):
JSON format (
--cli-error-format json):{ "Message": "Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed, None]", "Code": "TransactionCanceledException", "CancellationReasons": [ { "Code": "ConditionalCheckFailed", "Message": "The conditional request failed" }, { "Code": "None" } ] }YAML format (
--cli-error-format yaml):Simple error with additional fields
Command:
Enhanced format:
JSON format:
{ "Code": "NoSuchBucket", "Message": "The specified bucket does not exist", "BucketName": "not-a-real-bucket-0000" }Enhanced format behavior
The enhanced format handles different error shapes:
Simple values:
AllowedValues: [GET, PUT, POST, DELETE]Metadata: {key1: value1, key2: value2}Complex values:
When a field is complex, we show:
Configuration
Config file (
~/.aws/config):Environment variable:
export AWS_CLI_ERROR_FORMAT=yamlCommand-line flag:
Valid formats:
enhanced(default),json,yaml,text,table,legacyUse
legacyto get the old behavior with no structured error details.Technical notes
AWS services return modeled error fields at the top level of the error response, not nested under the
Errorkey. For example, DynamoDB returnsCancellationReasonsatresponse['CancellationReasons'], notresponse['Error']['CancellationReasons'].The implementation:
response['Error'](Code, Message, and any service-specific fields there)Tests
For reviewers
MAX_INLINE_ITEMS threshold:
Currently set to 5. Could be reduced to 4 for better terminal width compatibility, or we could add a character length limit (~70 chars) in addition to the item count. Open to feedback.
Sensitive data:
AWS service models include
@sensitivetraits for fields. Right now we display all error fields as returned by the service. Using the Smithy CLI to analyze AWS service models, I found 0 error response fields marked with@sensitivetraits.