Skip to content

find: report -print write errors on standard output - #908

Merged
sylvestre merged 2 commits into
uutils:mainfrom
SichenLiang:print-stdout-write-errors
Oct 23, 2026
Merged

sylvestre merged 2 commits into
uutils:mainfrom
SichenLiang:print-stdout-write-errors

Conversation

@SichenLiang

Copy link
Copy Markdown
Contributor

Follow-up to #905: -print, -print0, and the implicit print now use the same stdout error handler as -ls and -printf.

Before this change, the command returned 1 with no diagnostic. It now reports the error:

$ find . -maxdepth 0 > /dev/full; echo $?
find: 'standard output': No space left on device
1

The first write error is now reported once for the whole command, including when these actions are mixed with -ls or -printf. A broken pipe stops the walk and preserves any earlier nonzero status instead of returning 0. -fprint and -fprint0 are unchanged.

`-print`, `-print0`, and the implicit print returned 1 without a
diagnostic when a write to standard output failed. Route them through
the same handler as `-ls` and `-printf`, which reports the first error
once for the command.

A broken pipe now stops the walk and preserves an earlier exit status
instead of returning 0. `-fprint` and `-fprint0` are unchanged.
@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.54%. Comparing base (531c606) to head (cc5edf8).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #908   +/-   ##
=======================================
  Coverage   92.54%   92.54%           
=======================================
  Files          36       37    +1     
  Lines        7727     7754   +27     
  Branches      393      393           
=======================================
+ Hits         7151     7176   +25     
- Misses        436      437    +1     
- Partials      140      141    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 15 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 20 untouched benchmarks


Comparing SichenLiang:print-stdout-write-errors (cc5edf8) with main (70aad4d)

Open in CodSpeed

Comment thread src/find/matchers/printer.rs Outdated
)
.and_then(|()| out.flush());
if let Err(e) = result {
if !print_error_message {

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.

print_error_message now means "writing to stdout", maybe rename it or check self.output_file.is_none()?

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.

Done. The flag only had that one use I removed it and now check self.output_file.is_none() directly.

Comment thread tests/test_find.rs
&["-printf", "%p\n"],
&["-ls", "-printf", "%p\n"],
&["-print", "-ls"],
&["-print0", "-ls"],

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.

could you please add -print to find_stops_when_stdout_pipe_is_closed too? the broken pipe path changed as well

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.

Added. This case also passes on main because -print exits 0 on EPIPE before -fprint gets to write anything. It still guards the behavior changed

The `print_error_message` argument was only used to tell whether
`Printer::print` was writing to stdout. Check
`self.output_file.is_none()` instead and remove the argument.

Also add `-print` to the closed-pipe test.
@sylvestre
sylvestre merged commit b7a7cf1 into uutils:main Oct 23, 2026
34 checks passed
@sylvestre

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.

2 participants