← Back to Pull requests

numfmt: report warnings with show_error! #16854

Open
Abak2006 opened this pull request with 61 lines diff across 6 files
View on GitHub
Abak2006 Abak2006 commented on Nov 25, 2026 13:51 UTC
Author

Part of #16646. Depends on #16853. This branch includes that commit, so please review only the last commit.

numfmt printed its --debug warnings and --invalid=warn messages with its own let _ = writeln!(stderr(), "numfmt: ...") calls, which ignore write errors. So numfmt --debug 42 2>/dev/full exited 0, while GNU exits 1.

These calls now use show_error!, which prints the same numfmt: <message> line through print_diagnostic(). With #16853, that sets exit code 1 when the write fails. Output on stdout is unchanged, and normal runs still exit 0.

$ numfmt --debug 42 2>/dev/full; echo $?
42
1

Tests:

  • Added test_warning_write_error_sets_exit_code to test_numfmt.rs, covering --debug and --invalid=warn.

  • cargo test -p uu_numfmt and the test_numfmt integration tests pass; cargo fmt --check and clippy are clean.
  • Diff: 61 lines (+45 / -16) across 6 files Reviewer: xtqqczze Review duration: 13925m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.35) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.35 · 61 lines diff across 6 files
    0.35
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.91 · 3 substantive comment(s)
    0.91
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    91%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.247
    Real PR Conversation Timeline
    4 items
    xtqqczze xtqqczze commented on code on Nov 25, 2026 18:35 UTC
    Code Review
    src/uu/numfmt/src/numfmt.rs:1
    @@ -90,7 +90,7 @@ fn format_and_write(
                 show!(NumfmtError::FormattingError(msg));
             }
             InvalidModes::Warn => {
    -            let _ = writeln!(stderr(), "numfmt: {msg}");
    +            show_error!("{msg}");

    this no longer includes the utility name, no?

    codspeed[bot] codspeed[bot] commented on Nov 25, 2026 18:59 UTC
    Bot

    <!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->

    Merging this PR will improve performance by 17.59%

    <details>
    <summary><b>2 warnings, 1 note</b></summary>

    :warning: 125 benchmarks are dominated by system calls

    > System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

    > Learn more about system calls

    > See affected benchmarks

    :warning: 1 benchmark with a significant change ran on different hardware

    > Its base and head results were measured on machines with a different CPU, core count or memory, so the change might not come from the code. Run base and head on the same runner type.

    > Learn more about Macro Runners

    > See affected benchmarks

    :information_source: 1 benchmark has no flamegraph

    > The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

    > See affected benchmarks

    </details>

    ⚡ 1 improved benchmark
    ✅ 414 untouched benchmarks
    ⏩ 70 skipped benchmarks[^skipped]

    Performance Changes

    | | Mode | Benchmark | BASE | HEAD | Efficiency |
    | --- | ---- | --------- | ------ | ------ | ---------- |
    | ⚡ | Memory | [` cp_recursive_deep_tree[(120, 4)] ](https://app.codspeed.io/uutils/coreutils/branches/Abak2006%3Anumfmt-stderr-write-error?uri=src%2Fuu%2Fcp%2Fbenches%2Fcp_bench.rs%3A%3Acp_recursive_deep_tree%255B%28120%252C%25204%29%255D&runnerMode=Memory&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 789 KB | 671 KB | +17.59% |

    [!TIP]

    Curious why performance improved? Comment @codspeedbot explain why performance improved` on this PR, or directly use the CodSpeed MCP with your agent.

    ---

    <sub>Comparing <code>Abak2006:numfmt-stderr-write-error</code> (b42709a) with <code>main</code> (9ed1dfc)</sub>

    <a href="https://app.codspeed.io/uutils/coreutils/branches/Abak2006%3Anumfmt-stderr-write-error?utm_source=github&utm_medium=comment-v2&utm_content=button">
    <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
    <source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
    <img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
    </picture>
    </a>

    [^skipped]: 70 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.

    Abak2006 Abak2006 commented on code on Nov 25, 2026 19:06 UTC
    Code Review
    src/uu/numfmt/src/numfmt.rs:1
    @@ -90,7 +90,7 @@ fn format_and_write(
                 show!(NumfmtError::FormattingError(msg));
             }
             InvalidModes::Warn => {
    -            let _ = writeln!(stderr(), "numfmt: {msg}");
    +            show_error!("{msg}");

    show_error goes through print_diagnostic, which adds the util name, so it still prints "numfmt: ...". The existing warn and debug tests check for that prefix and they pass.

    Reviewers
    Assignees
    Abak2006 Abak2006
    Labels
    risk: low confidence: 91.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35% (MEDIUM) · Higher = larger blast radius
    35%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.5% · Lower = rushed or shallow review
    91.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3.0% · Safe to merge
    3.0%