Repository navigation
fix: honor redirects on function calls - #226
Merged
ferdingler merged 4 commits intoNov 11, 2026
Merged
Conversation
ferdingler
marked this pull request as ready for review
November 9, 2026 23:52
Collaborator
Author
|
@strandly-the-agent review |
strandly-the-agent
approved these changes
Nov 10, 2026
strandly-the-agent
left a comment
Collaborator
There was a problem hiding this comment.
Approve. Redirects on function calls now match bash for >, >>, 2>, <, heredocs, 2>&1 >f, return, set -e and unopenable targets, and eval/source behave exactly as before. Two 🟡 regressions come from routing functions through the buffering helper. Fix them here or track them with the ordering follow-up:
- 🟡 Redirected function output now counts against
max_output(1 MiB). Over it, the output is silently dropped or the call fails. - 🟡 Output from
&jobs started inside a redirected function is lost unless the functionwaits.
Verified at 7abe01e: cargo test --workspace --all-targets passed 2079, 0 failed. CI is green. I couldn't run cargo fmt or clippy locally because the components weren't installed, so CI is the only check for those.
Details: what I verified, questions, appendix
✅ Verified
- About 40 function-redirect cases, compared across main, this PR and bash, all match bash. That includes nested calls,
cd/vars kept,local/$@restored,break/continue,trap, recursion,$(f > o), and stdin inwhile read … done < in. - eval/source scripts give byte-identical output on main and this PR.
- 11 of the 14 new tests fail on main. The other 3 are regression guards.
Questions (non-blocking)
- Would it make sense to stream output to the redirect targets instead of buffering? That one change would fix both 🟡s and the
2>&1ordering follow-up. - Edition 2024 allows
F: AsyncFnOnce(&mut Process) -> Result<i32, ControlFlow>instead of the HRTBPin<Box<dyn Future>>bound. Optional; I didn't compile it.
Reading order: src/exec.rs:2604 (run_redirected), then :3211 (the call site).
Appendix: non-blocking / pre-existing (5)
- Pre-existing, from #196: write errors on the redirect target are dropped (
exec.rs:2667,let _ = writer.write_all(…)). Withmax_file_sizeset,f >> greturns 0 and leaves the file unchanged. This was raised on #196 and is still open. - Pre-existing:
exitinside a function doesn't exit the shell, with or without a redirect. #222 fixes that; if both merge, check theExitarm at:3235. - Pre-existing:
{ cat big; } 2>/dev/nullon its own, andeval … 2>/dev/nullin a pipeline, also produce empty output on main. The{ …; }case has the same root cause as the first 🟡. - ⚪ A body that reads its own redirect target doesn't see its own writes (
f >> logwherefrunstail log). eval does the same. - Out of scope: a redirect on a function definition (
f(){ …; } > e) is still ignored, same as on main.
ferdingler
enabled auto-merge (squash)
November 11, 2026 03:07
ferdingler
disabled auto-merge
November 11, 2026 03:07
3 tasks done
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
Redirects on a function call were ignored when the function ran as a plain command, so the output went to the terminal and the file was never created:
The same went for
2> fileand< file. Inside a function,readfailed because there was no stdin. Functions already worked in pipelines.Now the call applies its redirects the same way
evalandsourcealready do, and the function still runs in the current shell, socd, variables,returnandexitbehave as before. A function called without redirects takes exactly the same path as before. A redirected function's output is buffered until it returns, so with2>&1all of stdout comes before stderr, the same as{ ...; } > fileandevaltoday. Keeping the order is a follow-up. I leftVAR=value fprefixes for a separate PR.I compared each case against bash:
>,>>,2>,<, heredocs,2>&1 >file, nested calls,return 3, a target that can't be opened (the function doesn't run, status 1) andset -einside the function. The new tests fail on main and pass with the change. I also checked that this merges cleanly with #206.Related Issues
Part of #207
Documentation PR
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.