Skip to content

find: handle -fprintf write errors without panicking - #840

Merged
sylvestre merged 1 commit into
uutils:mainfrom
amoghsingh130:fix-fprintf-panic
Aug 18, 2026
Merged

find: handle -fprintf write errors without panicking#840
sylvestre merged 1 commit into
uutils:mainfrom
amoghsingh130:fix-fprintf-panic

Conversation

@amoghsingh130

Copy link
Copy Markdown
Contributor

Fixes #697.

-printf and -fprintf no longer panic when writing or flushing
output fails. The error is reported normally and find exits with
status 1. For -fprintf, the error also includes the output file.

Broken pipes still exit successfully.

Also added a unit test with a failing writer and a Linux regression test
using /dev/full.

@amoghsingh130
amoghsingh130 marked this pull request as ready for review August 17, 2026 04:15
Copilot AI lite review requested due to automatic review settings August 17, 2026 04:15

Copilot AI left a comment

Copy link
Copy Markdown

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 fixes a panic in find’s -printf/-fprintf actions when output writes/flushes fail (e.g., /dev/full), switching to normal error reporting and a non-zero exit status instead of unwinding.

Changes:

  • Propagate write/flush errors from the Printf matcher instead of unwrap() panics, and report errors to stderr with find: prefix.
  • Track the -fprintf output path so error messages can include the destination file.
  • Add regression tests: a unit test with a failing writer and a Linux-only integration test using /dev/full.

Reviewed changes

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

File Description
src/find/matchers/printf.rs Remove panics on write/flush; report write errors; include output path for -fprintf.
src/find/matchers/mod.rs Wire -fprintf to pass (File, PathBuf) into Printf.
tests/test_find.rs Add Linux regression test ensuring /dev/full write errors are reported without panicking.
Suppressed comments (1)

src/find/matchers/printf.rs:667

  • -fprintf write failures currently call matcher_io.quit(), which aborts the entire traversal on the first non-BrokenPipe output error. That can prevent subsequent actions with side effects (e.g. -delete, -exec) from running, and is also inconsistent with Printer, which sets exit status 1 but continues (see src/find/matchers/printer.rs:54-68). Consider only setting the exit code and letting the walk continue so other actions can still execute.
            matcher_io.set_exit_code(1);
            matcher_io.quit();

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

Comment thread src/find/matchers/printf.rs Outdated
Comment on lines +656 to +659
if error.kind() == std::io::ErrorKind::BrokenPipe {
matcher_io.quit();
return true;
}

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.

I agree that regular write errors stopping later actions. GNU find continues evaluating them and returns status 1 afterward, so I’ll remove quit() from that path.

However, I prefer to keep using MatcherIO instead of std::process::exit(). Matchers are library code, and exiting directly could hide an earlier unrelated failure. Leaving the existing status unchanged also keeps normal pipelines successful.

Copilot AI review requested due to automatic review settings August 17, 2026 04:36

Copilot AI left a comment

Copy link
Copy Markdown

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 3 out of 3 changed files in this pull request and generated no new comments.

@codecov

codecov Bot commented Aug 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.20%. Comparing base (2a3eac9) to head (19a2865).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #840      +/-   ##
==========================================
+ Coverage   92.15%   92.20%   +0.05%     
==========================================
  Files          35       35              
  Lines        7377     7417      +40     
  Branches      383      386       +3     
==========================================
+ Hits         6798     6839      +41     
+ Misses        438      437       -1     
  Partials      141      141              

☔ 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.

@github-actions

Copy link
Copy Markdown

Commit 810cf6b has test result changes:

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 312 / PASSED: 266 / FAILED: 40 / SKIPPED: 6
  Reference: TOTAL: 314 / PASSED: 266 / FAILED: 42 / SKIPPED: 6

Changes from main branch:
  TOTAL: -2
  PASSED: +0
  FAILED: -2

Test improvements (2):
  + gnu/files0_from_ok
  + gnu/okdir_path_empty

@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing amoghsingh130:fix-fprintf-panic (19a2865) with main (2a3eac9)

Open in CodSpeed

Copilot AI review requested due to automatic review settings August 17, 2026 21:19

Copilot AI left a comment

Copy link
Copy Markdown

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 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/find/matchers/printf.rs:650

  • BrokenPipe handling here only sets matcher_io.quit(). In process_dir, quitting breaks the main loop but still runs matcher.finished_dir(...) and matcher.finished(...), which can dispatch buffered -exec ... + commands and other side effects even though the output pipe is broken. This differs from Printer (which calls std::process::exit(0)) and can lead to unexpected side effects after a broken pipe.
    fn handle_output_error(&self, error: &std::io::Error, matcher_io: &mut MatcherIO) {
        if error.kind() == std::io::ErrorKind::BrokenPipe {
            matcher_io.quit();
            return;
        }

tests/test_find.rs:1166

  • This integration test asserts the OS error text "No space left on device", which can be localized and vary across environments. To keep the test stable, force the command locale to C (or assert on the numeric os error 28 portion instead).
    let result = ucmd()
        .args(&[".", "-maxdepth", "0", "-fprintf", "/dev/full", "%p\n"])
        .fails();
    result.no_stdout();
    let stderr = result.stderr_str();

    assert!(stderr.contains("find:"));
    assert!(stderr.contains("/dev/full"));
    assert!(stderr.contains("No space left on device"));
    assert!(!stderr.contains("panicked"));

@github-actions

Copy link
Copy Markdown

Commit d7352d8 has test result changes:

GNU findutils testsuite:

Test results comparison:
  Current:   TOTAL: 495 / PASSED: 420 / FAILED: 74 / SKIPPED: 1
  Reference: TOTAL: 495 / PASSED: 421 / FAILED: 73 / SKIPPED: 1

Changes from main branch:
  TOTAL: +0
  PASSED: -1
  FAILED: +1

New test failures (1):
  - size-invalid.new-O3

bfs testsuite:

Test results comparison:
  Current:   TOTAL: 314 / PASSED: 267 / FAILED: 41 / SKIPPED: 6
  Reference: TOTAL: 313 / PASSED: 267 / FAILED: 40 / SKIPPED: 6

Changes from main branch:
  TOTAL: +1
  PASSED: +0
  FAILED: +1

New test failures (1):
  - gnu/files0_from_ok

Copilot AI review requested due to automatic review settings August 18, 2026 17:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sylvestre
sylvestre merged commit 1acf40a into uutils:main Aug 18, 2026
23 checks passed
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.

bug: -fprintf with /dev/full find causes a panic

3 participants