Analyze bugs and errors of aws cli repo #10316
Open
andrey1bacelar-bit wants to merge 3 commits into
Open
Conversation
The f-string in ParamUnknownKeyError.__init__ referenced an undefined name `valid_key` (the parameter is named `valid_keys`). Any attempt to raise this exception failed with NameError instead of producing the intended "Unknown key '...', valid choices are: ..." message. Reference `valid_keys` and add a unit test that constructs the exception and asserts the formatted message contains both the offending key and the list of valid choices.
When a user passed a structure, map, or list parameter as a whitespace only string (for example `--filters " "`), `value.lstrip()[0]` in _unpack_complex_cli_arg accessed index 0 of an empty string and raised IndexError instead of producing the user-facing ParamError. Replace the index access with `lstrip().startswith(...)`, which is safe on empty input. A nearby branch for single-element lists already used a guarded check, so this aligns the three cases. Add regression tests covering whitespace-only structure and list string inputs.
One entry per bugfix, following the project's .changes/next-release JSON convention, so scripts/render-change can include them in the next release notes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi, my contribution to the AWS CLI project aimed to fix some bugs and errors. Some index and syntax problems were found in one of the files by my AI agent, Claude Code Opus 4.7, so I suggested this PR in light of this small problem. The text below was written by the agent; don't worry about any generated garbage, as I have skills and hooks to prevent it from happening.
Two independent error-path bugs in
awscli/argprocess.py, each addressed in its own commit with a regression test. Both are small, isolated fixes — no behavior change on the success path.1.
NameErrorinParamUnknownKeyError(commit f485d79)The f-string referenced an undefined name
valid_key; the parameter isvalid_keys, and the local variable is rebound to the joined string on the preceding line. Any attempt to raise this exception failed withNameErrorinstead of producing the intended message.Fixed line: https://github.com/andrey1bacelar-bit/aws-cli/blob/f485d79/awscli/argprocess.py#L58
The exception is reachable — it is caught at
awscli/argprocess.py:368— so the message formatting failure was a real user-visible regression on that error path.2.
IndexErroron whitespace-only complex arg values (commit 1688b97)_unpack_complex_cli_argusedvalue.lstrip()[0]to peek at the first non-whitespace character. With a whitespace-only string (for example--filters " "),lstrip()returns''and the index access crashed withIndexErrorinstead of the user-facingParamError.Fixed lines: https://github.com/andrey1bacelar-bit/aws-cli/blob/1688b97/awscli/argprocess.py#L188-L197
startswithis safe on empty input. A nearby branch for single-element lists already used a guarded check (if single_value and single_value[0] == '['), so this aligns the three cases.Test plan
tests/unit/test_argprocess.py:TestParamUnknownKeyError.test_message_includes_valid_keysTestUnpackComplexCliArgWhitespace.test_whitespace_only_structure_raises_param_errorTestUnpackComplexCliArgWhitespace.test_whitespace_only_list_string_raises_param_errorpython -m pytest tests/unit/test_argprocess.py— 68 passeddevelopbefore the fix (NameError/IndexErroras described above)Stats: +22 / −3 across 2 files.
owner: andrey1bacelar-bit
pullNumber: 1
repo: aws-cli
title: Fix NameError and IndexError in argprocess error paths
{"id":"3694752974","url":"https://github.com/andrey1bacelar-bit/aws-cli/pull/1"}