Skip to content

pr: report missing file as "pr: <file>: <message>"#13534

Merged
cakebaker merged 1 commit into
uutils:mainfrom
addielaruee:fix/13013-pr-error-message
Jul 23, 2026
Merged

pr: report missing file as "pr: <file>: <message>"#13534
cakebaker merged 1 commit into
uutils:mainfrom
addielaruee:fix/13013-pr-error-message

Conversation

@addielaruee

Copy link
Copy Markdown
Contributor

Fixes #13013

What

When pr is given a path it can't open, it currently prints:

$ pr qwe
pr: No such file or directory (os error 2)

The file name is missing and Rust's raw (os error N) suffix leaks. GNU pr prints the file name and no errno:

$ pr qwe
pr: qwe: No such file or directory

Change

read_to_end mapped std::fs::read errors into PrError through the generic From<io::Error> impl, which only calls to_string() — so the path (still in scope at the call) was lost and the errno suffix kept.

This adds a dedicated PrError::ReadError { path, msg } variant and builds the message in read_to_end, reusing the existing uucore::error::strip_errno() helper (the same pattern already used in head and sort).

Only the read path is changed, so write errors (e.g. pr file >/dev/full) keep their current behavior and are not prefixed with the file name, matching the discussion on the issue.

After:

$ pr qwe
pr: qwe: No such file or directory

Test

Adds test_missing_file_error_message. The exact OS message differs by platform (for example, "The system cannot find the file specified." on Windows), so the test asserts the portable behavior — the file name is present and the (os error N) suffix is stripped — rather than a hardcoded string.

cargo test, cargo clippy --all-targets, and cargo fmt --check all pass locally.


Note for triage: #13231 also targets this issue but has been stalled; its regression test hardcodes the Unix error string and fails on Windows CI. This PR is a minimal alternative that keeps a platform-independent test.

std::fs::read errors were converted to PrError via to_string(), which
dropped the file name and kept Rust's raw "(os error N)" suffix, so
`pr nonexistent` printed "pr: No such file or directory (os error 2)".

Attach the path and strip the errno with the existing uucore
strip_errno() helper so the message matches GNU pr:
"pr: nonexistent: No such file or directory".
@codspeed-hq

codspeed-hq Bot commented Jul 23, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 3.53%

⚡ 1 improved benchmark
✅ 338 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ls_recursive_balanced_tree[(6, 4, 15)] 51.2 ms 49.4 ms +3.53%

Tip

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


Comparing addielaruee:fix/13013-pr-error-message (d400d44) with main (70406bc)2

Open in CodSpeed

Footnotes

  1. 46 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.

  2. No successful run was found on main (bcb1d28) during the generation of this report, so 70406bc was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@cakebaker
cakebaker merged commit 4be96c1 into uutils:main Jul 23, 2026
164 checks passed
@cakebaker

Copy link
Copy Markdown
Contributor

Thanks for your PR!

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.

pr: bad error message when directory doesn't exist

2 participants