Repository navigation
fix(shell): keep the Nushell wrapper working when its stdout is redirected - #4525
Merged
Merged
Conversation
…ected Since #4400 rewrote templates/nushell.nu around `try … finally`, a redirected call whose command prints nothing to stdout, such as `wt switch --create y o> /dev/null`, fails with "can't convert nothing to string" at the `try {`, stops the script, and loses the directory change. v0.80.0 handled it. Nushell (0.116) fails converting a `try … finally` that evaluates to nothing under `o>` or `o+e>`; plain `try`, `| ignore` and `e>` are unaffected. The `try … finally` now evaluates to a record of the exit code and captured stdout, and the wrapper returns stdout or propagates the failure after it, as v0.80.0 did. A failure's stdout still prints inside the block, so a failing cd directive can't drop it, and the `finally` still applies the directive and removes the temp files on Ctrl-C. Returning an empty string instead would have printed a blank line after every non-redirected `wt switch` run as a script's last command. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
worktrunk-bot
approved these changes
Oct 20, 2026
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.
Since #4400 rewrote the Nushell wrapper around
try … finally, redirecting the stdout of awtcommand that prints nothing there aborts the wrapper.nu --no-config-file -c 'source init.nu; cd repo; wt switch --create y o> /dev/null; print $env.PWD'printsrepo.yon v0.80.0, but on main it fails withnu::shell::cant_convert ... can't convert nothing to stringat thetry {, stops the script, and loses the cd.Nushell 0.116 fails to convert a
try … finallythat evaluates to nothing undero>oro+e>. A plaintry,| ignoreande>are unaffected. The wrapper'stry … finallynow evaluates to a record holding the exit code and captured stdout, and the wrapper returns stdout or propagates the failure after the block, as v0.80.0 did. A failure's stdout still prints inside the block, so a failing cd directive can't drop it, and thefinallystill applies the directive and removes the temp files on Ctrl-C. Returning""from the empty branch would also have avoided the error, but it prints a blank line whenwt switchis the last command of anu -cscript.Verified with nu 0.116.0 against v0.80.0, main and this branch:
o> /dev/null,o> file,| ignore,e> /dev/null,o+e> /dev/null, plain and captured (let x = (wt switch …)) calls, a stdout-producing command redirected and piped, a failing command (exit 1 with no source trace, with and withouto>), and--executeundero>all match v0.80.0 on this branch. Main fails theo> /dev/null,o> file,o+e>and--executeundero>cases. An interactive PTY session runswt switchwith and withouto> /dev/nulland changes directory both times. The newtest_nu_wrapper_redirected_stdout_applies_cdfails on main with the samecant_converterror and passes here. The nushell, shell-wrapper, init and foreground-job integration tests (291) pass with--features shell-integration-tests.