Skip to content

Make command-line flag parsing robust to lookalike flags and bad values - #159

Merged
giordano merged 1 commit into
mainfrom
mg/parse-args-errors-for-real
Aug 8, 2026
Merged

Make command-line flag parsing robust to lookalike flags and bad values#159
giordano merged 1 commit into
mainfrom
mg/parse-args-errors-for-real

Conversation

@giordano

@giordano giordano commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

`extract_flag!` matched flags with `startswith` and unconditionally indexed
the second element of an unbounded `split` on `=`, so:

- `--verbose-foo` threw a BoundsError instead of the friendly "Unknown test
  options" message;
- a custom flag extending a builtin's name (e.g. `--listing` vs `--list`)
  was captured by the builtin, also throwing a BoundsError;
- `--jobs2=3` was silently accepted as `--jobs=3`;
- a bare `--jobs` crashed with a MethodError when `Some(nothing)` hit the
  `Some{Int}` field of `ParsedArgs`, and `--jobs=abc` leaked a raw
  ArgumentError from `parse`;
- values containing `=` (e.g. `--format=key=value`) were truncated.

Match only the exact flag or `--flag=value`, split with `limit=2`, and turn
missing or unparseable values into clean error messages. Also reject values
passed to the boolean flags `--verbose`/`--quickfail`/`--list`, which
previously crashed with a MethodError during ParsedArgs construction.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread src/ParallelTestRunner.jl
Comment on lines +766 to +771
# boolean flags don't take values
for (flag, val) in (("--verbose", verbose), ("--quickfail", quickfail), ("--list", list))
if val isa Some && something(val) !== nothing
error("Option `$flag` does not take a value")
end
end

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it'd be a bad idea to accept things like --verbose={true,false}, but currently these flags don't accept any value and error badly anyway, at least this gives a nice and clear error message.

@giordano
giordano merged commit 4d7043e into main Aug 8, 2026
23 checks passed
@giordano
giordano deleted the mg/parse-args-errors-for-real branch August 8, 2026 20:58
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.

1 participant