mirror of
https://github.com/max-sixty/worktrunk.git
synced 2026-11-22 00:52:51 +08:00
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_ --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>