Skip to content

fix(cli): report a --data value without "=" as a usage error - #2121

Open
qianeric-backup wants to merge 1 commit into
pyinfra-dev:3.xfrom
qianeric-backup:fix/data-argument-without-equals
Open

qianeric-backup wants to merge 1 commit into
pyinfra-dev:3.xfrom
qianeric-backup:fix/data-argument-without-equals

Conversation

@qianeric-backup

Copy link
Copy Markdown

pyinfra @local debug-inventory --data foo (a --data value without the =value part) is reported as an internal error:

$ pyinfra @local debug-inventory --data foo
--> Loading config...
╭───────────────────────────── Traceback ──────────────────────────────╮
│ .../pyinfra_cli/cli.py                                               │
╰──────────────────────────────────────────────────────────────────────╯
ValueError: not enough values to unpack (expected 2, got 1)
--> The full traceback has been written to pyinfra-debug.log
--> If this is unexpected please consider submitting a bug report on GitHub, ...

_set_override_data() unpacks arg.split("=", 1) without checking that the separator is there, so a typo becomes a bare ValueError that reaches the top-level handler and is reported as a bug in pyinfra. The key=value contract is already documented on the option itself:

@click.option("--data", ..., help="Add data to the deploy, e.g. `--data key=value`.")

After:

$ pyinfra @local debug-inventory --data foo
--> Loading config...
--> pyinfra error: Invalid data argument: `foo`, should be in the format `key=value`
$ echo $?
1

No pyinfra-debug.log, no traceback, no "submit a bug report" prompt — the exit code is unchanged and the message is a CliError, the same type the neighbouring argument paths raise (pyinfra_cli/cli.py:324, :649, :661). pyinfra_cli/commands.py:47 guards the identical key=value unpack with if "=" in command:, so the missing separator is already treated as a user error elsewhere.

This mirrors the earlier fix of the same shape, fix(cli): raise clear error for missing inventory files (#2095).

--data key=value, --data key=a=b (value containing =) and the no---data path are unchanged — verified byte-for-byte against the unpatched tree.

Tests

tests/test_cli/test_cli.py::TestCliOverrideData — three cases: a value without = raises, key=value is accepted, and key=a=b keeps the split("=", 1) semantics. The first fails without the change and all three pass with it. Suite: 1 failed, 2308 passed → 2309 passed; ruff check / ruff format --check clean on both trees.

AI usage

This change was produced with an AI coding assistant (Claude), used to locate the traceback path, write the guard and the tests, and run the before/after verification. Every line was reviewed and the behaviour above was re-checked by hand against the unpatched tree.

_set_override_data() unpacks arg.split("=", 1) without checking that the
separator is there, so `--data foo` raises a bare ValueError that the
top-level handler reports as an internal error, complete with a Rich
traceback, a pyinfra-debug.log and a request to file a bug report.

Raise a CliError with the documented key=value format instead.
@wowi42 wowi42 added bug Label for all kind of bugs. CLI CLI mode specific issues. labels Nov 27, 2026
@qianeric-backup
qianeric-backup marked this pull request as ready for review November 27, 2026 06:00

This branch has not been deployed

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

Labels

bug Label for all kind of bugs. CLI CLI mode specific issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants