Repository navigation
fix(find): forward -exec child stderr - #227
Merged
Merged
Conversation
ferdingler
marked this pull request as ready for review
November 9, 2026 23:51
9 of 10 tasks
Collaborator
Author
|
@strandly-the-agent please review |
10 tasks done
strandly-the-agent
approved these changes
Nov 12, 2026
strandly-the-agent
left a comment
Collaborator
There was a problem hiding this comment.
Approve. The fix is correct and matches #213 (xargs) line for line: io::stderr().ok(), with the child's stderr written right after its stdout. I found no blocking issues.
Taking fd 2 is safe here. proc.err_msg writes through err_tx, not the fd table, and find's only err_msg (the parse error, find.rs:365) runs before the take. Children that write to >&2 themselves (functions, sourced scripts) still forward correctly, and I saw no bad fd 2 errors.
What I verified
- Head
b1286d2.cargo test --test shell_integration find_execgives 13 passed. With the source reverted, 6 of those fail, so the new tests catch the bug. The fullshell_integrationsuite passes (1595). - I compared PR and main binaries by hand. The PR now forwards stderr through
2>&1,$(… 2>&1),2>/dev/null,2>file,2>&1 >/dev/null |, function and{ }group redirects, two-execs per file (ordering),+(a b err, same as GNU), and nestedfind -exec find -exec.2>&-and>&-behave the same as on main. 10k lines of child stderr give no hang or truncation. - Probe log:
strands-agents/shell/pr/227/find-exec-stderr-probes.txt(artifacts).
Non-blocking (2)
- ⚪ Inside one child, stdout and stderr are buffered separately, so
g(){ echo o1; echo e1 >&2; echo o2; }; find f -exec g \; 2>&1giveso1 o2 e1where GNU giveso1 e1 o2. This comes fromcapture = trueinexec_fork, and #213 does the same. It's still a strict improvement over droppinge1, and it might be worth a line in the PR body. - ⚪ Because the stderr write uses
?, find stops at the first failed write when the stderr reader has gone away (find d -exec g {} \; 2>&1 >o.txt | trueleaves 1 line ino.txt; main leaves 10). This is how find's stdout writes already behave, and how GNU find behaves under SIGPIPE, so I'd leave it.
Newly visible, and already broken on main (not caused by this PR): -exec xargs … now shows xargs: bad fd 0, and -exec sh -c … shows -c: no such file or directory. Main hid both of these because it dropped stderr.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
find -execpassed on the command's stdout but quietly dropped its stderr. So if the command failed you saw nothing, where GNU find shows the error:Now find writes each command's stderr right after its stdout, for both
\;and+. Redirects on the find itself apply to it too, so2>/dev/null,2>fileand2>&1 |all work. This is the same fix as #213 for xargs. I didn't touch find's exit status. GNU returns 1 when a+command fails and we still return 0, so that's left for a separate fix.I added tests for both forms, a missing command, the three redirects, stdout staying the same, and the order of output when two
-execs run on each file. On main the forwarding tests fail, and with the change everything passes. The example above now printsstrands-shell: cat: no such file or directory: /nope. I also tried a smaller version that sends the stderr through the shell's error-message path, but it lost messages once a second-execran, and the ordering test caught that.Related Issues
Part of #207
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.