Skip to content

NameError in ParamUnknownKeyError due to undefined variable valid_key #10405

Closed

Description

@Dreamstick9

Describe the bug

When the CLI attempts to raise a ParamUnknownKeyError (typically during map/shorthand validation), a NameError is thrown instead. This occurs due to a typo in awscli/argprocess.py (line 58), where valid_key is used instead of the locally defined valid_keys variable.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

The CLI should successfully format and raise a ParamUnknownKeyError, displaying a clear error message that lists the invalid key alongside the valid choices.

Current Behavior

A NameError is thrown because valid_key is not defined in the local scope, masking the intended CLI parsing error.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from awscli.argprocess import ParamUnknownKeyError; ParamUnknownKeyError('BadKey', ['GoodKey1', 'GoodKey2'])
                                                        ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kushagargargsmacbook/aws-cli/awscli/argprocess.py", line 58, in __init__
    f"Unknown key '{key}', valid choices are: {valid_key}"
                                               ^^^^^^^^^
NameError: name 'valid_key' is not defined. Did you mean: 'valid_keys'?

Reproduction Steps

This bug can be cleanly isolated and reproduced directly by instantiating the error class in a Python REPL:

python3 -c "from awscli.argprocess import ParamUnknownKeyError; ParamUnknownKeyError('BadKey', ['GoodKey1', 'GoodKey2'])"

Possible Solution

Change the variable name from valid_key to valid_keys on line 58 of awscli/argprocess.py.

# Current
f"Unknown key '{key}', valid choices are: {valid_key}"

# Proposed Fix
f"Unknown key '{key}', valid choices are: {valid_keys}"

Additional Information/Context

I have tested this fix locally and will be opening a Pull Request shortly to address it.

CLI version used

aws-cli/1.45.29 Python/3.12.1 botocore/1.43.29

Environment details (OS name and version, etc.)

macOS / Linux (6.8.0-1052-azure)

Activity

  1. added
    bugThis issue is a bug.
    needs-triageThis issue or PR still needs to be triaged.
    on Jun 13, 2026
  2. added a commit that references this issue on Jun 19, 2026
    38075c4
  3. github-actions commented on Jun 19, 2026

    @github-actions
    Contributor

    This issue is now closed. Comments on closed issues are hard for our team to see.
    If you need more assistance, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions