Skip to content

Analyze bugs and errors of aws cli repo #10316

Open
andrey1bacelar-bit wants to merge 3 commits into
aws:developfrom
andrey1bacelar-bit:claude/analyze-aws-cli-repo-wV6o5
Open

Analyze bugs and errors of aws cli repo #10316
andrey1bacelar-bit wants to merge 3 commits into
aws:developfrom
andrey1bacelar-bit:claude/analyze-aws-cli-repo-wV6o5

Conversation

@andrey1bacelar-bit
Copy link
Copy Markdown

@andrey1bacelar-bit andrey1bacelar-bit commented May 16, 2026

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. NameError in ParamUnknownKeyError (commit f485d79)

The f-string referenced an undefined name valid_key; the parameter is valid_keys, and the local variable is rebound to the joined string on the preceding line. Any attempt to raise this exception failed with NameError instead of producing the intended message.

Fixed line: https://github.com/andrey1bacelar-bit/aws-cli/blob/f485d79/awscli/argprocess.py#L58

-            f"Unknown key '{key}', valid choices are: {valid_key}"
+            f"Unknown key '{key}', valid choices are: {valid_keys}"

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. IndexError on whitespace-only complex arg values (commit 1688b97)

_unpack_complex_cli_arg used value.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 with IndexError instead of the user-facing ParamError.

Fixed lines: https://github.com/andrey1bacelar-bit/aws-cli/blob/1688b97/awscli/argprocess.py#L188-L197

     if type_name == 'structure' or type_name == 'map':
-        if value.lstrip()[0] == '{':
+        if value.lstrip().startswith('{'):
             return _unpack_json_cli_arg(argument_model, value, cli_name)
         raise ParamError(cli_name, f"Invalid JSON:\n{value}")
     elif type_name == 'list':
         if isinstance(value, str):
-            if value.lstrip()[0] == '[':
+            if value.lstrip().startswith('['):
                 return _unpack_json_cli_arg(argument_model, value, cli_name)

startswith is 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

  • Added regression tests in tests/unit/test_argprocess.py:
    • TestParamUnknownKeyError.test_message_includes_valid_keys
    • TestUnpackComplexCliArgWhitespace.test_whitespace_only_structure_raises_param_error
    • TestUnpackComplexCliArgWhitespace.test_whitespace_only_list_string_raises_param_error
  • python -m pytest tests/unit/test_argprocess.py68 passed
  • Verified both bugs reproduce on develop before the fix (NameError / IndexError as described above)
  • Full unit suite green in CI

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"}

claude added 3 commits May 16, 2026 14:47
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.
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