Skip to content

base32, base64, basenc: drop the "error: " from the invalid-input message - #14396

Open
Socialpranker wants to merge 1 commit into
uutils:mainfrom
Socialpranker:base-drop-error-prefix
Open

base32, base64, basenc: drop the "error: " from the invalid-input message#14396
Socialpranker wants to merge 1 commit into
uutils:mainfrom
Socialpranker:base-drop-error-prefix

Conversation

@Socialpranker

Copy link
Copy Markdown
Contributor

The invalid-input diagnostic carried a literal error: on top of the
program name that uucore already prints:

$ printf 'not base64!' | base64 -d            # GNU
base64: invalid input
$ printf 'not base64!' | base64 -d            # uutils, before
base64: error: invalid input

$ printf 'abc' | basenc --z85                 # GNU
basenc: invalid input (length must be multiple of 4 characters)
$ printf 'abc' | basenc --z85                 # uutils, before
basenc: error: invalid input (length must be multiple of 4 characters)

No other diagnostic in these utilities spells the word "error" — the
neighbouring messages are basenc: missing encoding type,
base64: extra operand, and so on — and none of the GNU ones do either.

The fix

Dropping the prefix from the 13 message literals in
src/uucore/src/lib/features/encoding.rs and
src/uu/base32/src/base_common.rs, and from the seven test assertions
that pinned the old wording. Nothing else changes: same error kind, same
exit status 1, same trailing detail in the z85 length message.

Not addressed here: GNU also writes the successfully decoded prefix to
stdout before failing, which uutils does not — that is #6008 and is left
alone.

How the GNU behavior was established

By running the installed GNU coreutils 9.11 binaries (Homebrew, gbase32,
gbase64, gbasenc) as a black box on undecodable input across
--base64, --base64url, --base32, --base32hex, --base16, --z85
and the plain base32 -d / base64 -d forms, and diffing stderr against
uutils. I did not read GNU coreutils source.

Testing

  • The seven existing assertions in tests/by-util/test_base32.rs,
    test_base64.rs and test_basenc.rs now pin the GNU wording, so they
    are the mutation check: reverting the two source files alone makes all
    seven fail.
  • cargo test --features "base32 base64 basenc" --test tests test_base:
    119 passed, 0 failed.
  • cargo clippy -p uu_base32 -p uu_base64 -p uu_basenc --all-targets -- -D warnings:
    clean.
  • cargo fmt --check: clean.
  • Differential A/B against GNU coreutils 9.11 over 713 invocations across
    28 utilities: mismatches 79 -> 74 (base32 1 -> 0, basenc 6 -> 2), no
    other bucket moved. The four that remain in these utilities are the
    partial-output difference of basenc: emit partial output on invalid input #6008.

Disclosure

Prepared with AI assistance (Claude Opus 5, via Claude Code), per the AI
policy in CONTRIBUTING.md. Every GNU behavior quoted above came from
running the installed binaries, not from reading GPL source. All testing
was run locally.

@Socialpranker

Copy link
Copy Markdown
Contributor Author

Pushed one more commit: util/build-gnu.sh patched tests/basenc/basenc.pl to add error: to the upstream expectation, so that sed is now obsolete and removed — the GNU test expects what uutils prints.

For the record, the one red job here (Build (ubuntu-latest, i686-unknown-linux-gnu, …)) is test_numfmt::test_unit_hyphen_leading_as_separate_arg panicking on failed to write to stdin of child: Broken pipe — a test-harness race in an unrelated utility, not something this change can reach.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/csplit/csplit-heap is now being skipped but was previously passing.

@anastygnome

Copy link
Copy Markdown
Contributor

Could you please squash your commits ? Thanks

@anastygnome anastygnome left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be localised as done in other utils

} else if ignore_garbage {
continue;
} else {
return Err(USimpleError::new(1, "error: invalid input"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SHould be localised

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Localised as base-common-invalid-input in base_common.rs/.ftl, sha a8d7da6.

if !input.len().is_multiple_of(4) {
return Err(USimpleError::new(
1,
"error: invalid input (length must be multiple of 4 characters)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should be localised too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Localised as encoding-error-invalid-input/encoding-error-invalid-input-z85-length in uucore/encoding.rs/.ftl, sha a8d7da6.

…sage

The diagnostic already carries the program name, so the extra literal
made it read "base64: error: invalid input" where GNU writes
"base64: invalid input".
@Socialpranker

Copy link
Copy Markdown
Contributor Author

Squashed to a single commit, sha a8d7da6.

@codspeed-hq

codspeed-hq Bot commented Sep 5, 2026

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚡ 6 improved benchmarks
❌ 2 regressed benchmarks
✅ 359 untouched benchmarks
⏩ 50 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation mv_directory 8.2 ms 8.5 ms -3.52%
Simulation wc_bytes_synthetic[500] 161.7 µs 167.6 µs -3.52%
Simulation mv_force_overwrite 177.9 ms 147.5 ms +20.61%
Simulation hostname_ip_lookup[100000] 179 µs 164.4 µs +8.85%
Simulation cksum_crc 34 ms 32.5 ms +4.69%
Simulation cksum_default 33.7 ms 32.4 ms +3.83%
Simulation cksum_raw_output 33.7 ms 32.7 ms +3.14%
Simulation cksum_multiple_files 50.4 ms 48.9 ms +3.05%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Socialpranker:base-drop-error-prefix (a8d7da6) with main (9ff4114)

Open in CodSpeed

Footnotes

  1. 50 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@anastygnome

Copy link
Copy Markdown
Contributor

Flaky CI

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