Skip to content

sort: report read failures with context - #14005

Open
arcusbuilds wants to merge 1 commit into
uutils:mainfrom
arcusbuilds:fix/sort-read-error-message
Open

sort: report read failures with context#14005
arcusbuilds wants to merge 1 commit into
uutils:mainfrom
arcusbuilds:fix/sort-read-error-message

Conversation

@arcusbuilds

@arcusbuilds arcusbuilds commented Aug 18, 2026

Copy link
Copy Markdown

Fixes #13992.

sort /proc/self/mem reported the read failure as the bare io::Error string:

sort: Input/output error (os error 5)

That names neither the operation that failed nor anything the user can act on, and the (os error 5) suffix is noise. GNU prints sort: read failed: /proc/self/mem: Input/output error for the same input.

chunks.rs was calling e.to_string() directly. This wraps it with a read failed context and drops the errno suffix using the existing strip_errno helper, matching how the other SortError variants are rendered:

sort: read failed: Input/output error

It deliberately stops short of naming the file. read_to_buffer takes &mut T: Read, and ext_sort hands it an iterator of already-opened readers, so the path is gone by the time a read fails. Carrying it through would mean changing that iterator's item type and threading a PathBuf through chunks.rs and ext_sort/{mod,threaded,wasi}.rs. That is worth doing, but it is a much wider diff and I did not want to bundle the two. I am happy to follow up with it, or to fold it into this PR if you would rather have the whole fix at once.

The existing sort-cannot-read string is also worded cannot read: {$path}: {$error} rather than read failed:, so a path-carrying version would need either a reworded key or a new one. That is another reason to keep the change separate.

Tests: test_read_error_message in tests/by-util/test_sort.rs, Linux-only since it relies on /proc/self/mem returning EIO. It fails on main with the old message and passes here. The full test_sort suite is green (187 passed), and cargo fmt --check and cargo clippy -p uu_sort --all-targets -- -D warnings are both clean.

Copilot AI lite review requested due to automatic review settings August 18, 2026 19:36

Copilot AI 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.

Pull request overview

This PR improves sort’s user-facing error reporting for input read failures by adding a dedicated localized message that includes context (“read failed”) and strips Rust’s trailing "(os error N)" suffix, along with an integration test that locks in the new output.

Changes:

  • Wrap read errors in chunks.rs with a read failed context message and format the underlying io::Error via strip_errno.
  • Add a new Fluent localization key sort-read-failed for the new message.
  • Add a Linux-only regression test using /proc/self/mem to verify the exact stderr output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/by-util/test_sort.rs Adds a Linux-only regression test asserting the improved read-failure message formatting.
src/uu/sort/src/chunks.rs Replaces raw io::Error::to_string() with a translated, contextualized error message using strip_errno.
src/uu/sort/locales/en-US.ftl Introduces the new sort-read-failed localization string used by the new error path.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/uu/sort/locales/en-US.ftl
A read error was reported as the bare io::Error string, e.g.
`sort: Input/output error (os error 5)` for `sort /proc/self/mem`.
That names neither the operation that failed nor anything the user
can act on, and the `(os error 5)` suffix is noise.

Wrap it with a "read failed" context and drop the errno suffix using
the existing strip_errno helper, matching the style of the other
SortError variants:

    sort: read failed: Input/output error

Fixes uutils#13992
@arcusbuilds
arcusbuilds force-pushed the fix/sort-read-error-message branch from 7c16a97 to f9dbbd3 Compare August 18, 2026 19:42
Copilot AI review requested due to automatic review settings August 18, 2026 19:42

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@codspeed-hq

codspeed-hq Bot commented Aug 19, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.72%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 355 untouched benchmarks
⏩ 50 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation cksum_crc 41.4 ms 43.1 ms -3.86%
Simulation numfmt_stream_to_si_precision 346.4 ms 359.2 ms -3.59%

Tip

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


Comparing arcusbuilds:fix/sort-read-error-message (f9dbbd3) with main (1a36740)

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.

@github-actions

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/inotify-dir-recreate (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)

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.

sort: i/o error should be stripped

2 participants