Skip to content

fix(shell): keep the Nushell wrapper working when its stdout is redirected - #4525

Merged
max-sixty merged 3 commits into
mainfrom
fix/nushell-redirected-stdout
Oct 20, 2026
Merged

max-sixty merged 3 commits into
mainfrom
fix/nushell-redirected-stdout

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Since #4400 rewrote the Nushell wrapper around try … finally, redirecting the stdout of a wt command 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' prints repo.y on v0.80.0, but on main it fails with nu::shell::cant_convert ... can't convert nothing to string at the try {, stops the script, and loses the cd.

Nushell 0.116 fails to convert a try … finally that evaluates to nothing under o> or o+e>. A plain try, | ignore and e> are unaffected. The wrapper's try … finally now 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 the finally still 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 when wt switch is the last command of a nu -c script.

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 without o>), and --execute under o> all match v0.80.0 on this branch. Main fails the o> /dev/null, o> file, o+e> and --execute under o> cases. An interactive PTY session runs wt switch with and without o> /dev/null and changes directory both times. The new test_nu_wrapper_redirected_stdout_applies_cd fails on main with the same cant_convert error and passes here. The nushell, shell-wrapper, init and foreground-job integration tests (291) pass with --features shell-integration-tests.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 3 commits October 19, 2026 22:37
…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]>
@max-sixty
max-sixty merged commit 12d33b3 into main Oct 20, 2026
38 checks passed
@max-sixty
max-sixty deleted the fix/nushell-redirected-stdout branch October 20, 2026 15:40
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