Skip to content

tee: match GNU's error for a bad --output-error value - #14308

Open
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/tee-output-error-invalid-choice
Open

tee: match GNU's error for a bad --output-error value#14308
arbelonson-source wants to merge 1 commit into
uutils:mainfrom
arbelonson-source:fix/tee-output-error-invalid-choice

Conversation

@arbelonson-source

Copy link
Copy Markdown
Contributor

What

An unrecognized or ambiguous --output-error value produces clap's
own generic wording instead of GNU's:

$ echo hi | tee --output-error=bogus f

# GNU
tee: invalid argument 'bogus' for '--output-error'
Valid arguments are:
  - 'warn'
  - 'warn-nopipe'
  - 'exit'
  - 'exit-nopipe'
Try 'tee --help' for more information.

# uutils, before this PR
error: invalid value 'bogus' for '--output-error[=<output-error>]'

  [possible values: warn, warn-nopipe, exit, exit-nopipe]

For more information, try '--help'.

Fix

Unlike the other options fixed in this same series (#14293, #14303,
#14304, #14305, #14306, #14307), --output-error keeps its
ShortcutValueParser rather than being resolved by hand: each of its
choices carries its own description, rendered as clap's "Possible
values:" block in --help, e.g.:

      --output-error[=<output-error>]
          set write error behavior

          Possible values:
          - warn:        produce warnings for errors writing to any output
          - warn-nopipe: produce warnings for errors that are not pipe errors ...
          ...

That per-choice text only a value_parser can supply to clap's help
renderer, so dropping the parser (as the other fixes in this series
do) would either lose that --help output or require hand-rolling
the same metadata a second time just to feed it back to clap for
display -- not worth it for one option. Instead, this intercepts a
rejection specifically on --output-error right after parsing and
re-reports it with GNU's wording (checking for an exact match first,
since warn and exit are themselves prefixes of warn-nopipe and
exit-nopipe); every other clap error -- unknown flags, --help,
--version, etc. -- still goes through the exact same shared
formatter as before, unchanged.

Testing

  • cargo test -p uu_tee / full tests/by-util/test_tee.rs suite: 37 passed, 0 failed.
  • Added 2 regression tests: an invalid value and an ambiguous one (wa, between warn and warn-nopipe).
  • Manually diffed every --output-error value (all real choices/abbreviations, invalid, ambiguous, empty) against GNU tee 9.11 under LC_ALL=C.
  • Manually confirmed --help/-h/--version and unrelated errors (e.g. an unknown flag) are unaffected.
  • cargo clippy -p uu_tee --all-targets -- -D warnings and cargo fmt --check: clean.

This PR was written with AI assistance (Claude Opus 5, via Claude Code). I've tested the changes but please review the code carefully.

An unrecognized or ambiguous --output-error value produced clap's own
generic wording instead of GNU's ('invalid argument ... for
--output-error / Valid arguments are: / - 'warn' / ...').

Unlike the other options fixed in this series (uutils#14293, uutils#14303,
uutils#14304, uutils#14305, uutils#14306, uutils#14307), --output-error keeps its
ShortcutValueParser rather than being resolved by hand: each of its
choices carries its own description (clap's 'Possible values:' block
in --help), which only a value_parser can supply, and hand-rolling
that metadata a second time to drop the parser would only recreate
what it already provides. Instead, intercept a rejection specifically
on this argument after parsing and re-report it with GNU's wording
(checking for an exact match first, since 'warn' and 'exit' are
themselves prefixes of 'warn-nopipe' and 'exit-nopipe'); every other
clap error still goes through the shared formatter unchanged.

AI-assisted-by: Claude Opus 5, via Claude Code
@oech3

oech3 commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

We tries to show error message better than GNU. So clap provided errors itself are not issue about compatibility.
clap has more infomation generally.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/pr/bounded-memory (was skipped on 'main', now failing)

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