Skip to content

Run catch when try is piped into ignore, complete, save or tee - #19647

Merged
fdncred merged 1 commit into
nushell:mainfrom
fdncred:try_catch_error_value
Nov 24, 2026
Merged

fdncred merged 1 commit into
nushell:mainfrom
fdncred:try_catch_error_value

Conversation

@fdncred

@fdncred fdncred commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Description

Since 0.114.0, try skips catch when it's piped into ignore, complete, save or tee and the error comes from the last command in its block. finally still runs, but it gets the raw error as its input and parameter, so the first command there that reads either one raises the error again. The case most likely to bite is a custom command that ends in a try. Call it as my-command | ignore and its catch never runs.

#18306 made a command return its error as a value when its stderr goes to a separate pipe. That lets ignore --stderr decide what to do with the error. All four commands above ask for that separate pipe, and the last command in a try block inherits the redirection of whatever follows the try. So the error turned into a value, passed through try without reaching catch, and the next command raised it. Up to 0.117.0, a ; after the pipeline discarded the error. #19467 stopped that, so on main the error surfaces.

try now raises an error value that reaches the end of its block, or the end of catch before finally. The handlers run the same as they do without the pipe. When only finally handles the error, finally gets the error record. Then the error goes on to the next command as a value, the same as without finally, so ignore --stderr still consumes it.

User-facing changes (Release notes)

  • Fixed try skipping catch when it's piped into ignore, complete, save or tee, including through a custom command that ends in a try. In the same case finally now gets the error record instead of the raw error. This was a regression in 0.114.0.
  • try { ... } catch { 'fallback' } | ignore --stderr now passes on fallback instead of consuming the error, and try { exit 3 } | ignore --stderr now exits.

Additional notes

…`tee`

The last call in a `try` block runs with the stderr mode of the command
after the `try`. Since nushell#18306, a failing call returns its error as a value
when that command is `complete`, `ignore`, `save` or `tee`, so the error
passed through the `try` without reaching `catch`, and `finally` got the
raw error value.

`try-collect` and `drain-if-end` now raise an error value, so the handlers
run as they do without the pipe. When only `finally` handles it, the error
goes back into the `try`'s register as a value after `end-finally`, so the
next command still sees it the same way as without `finally` (for example,
`ignore --stderr` still consumes it). `break`, `continue` and `exit` stay
plain errors.
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Nov 24, 2026
@fdncred
fdncred merged commit b85aa73 into nushell:main Nov 24, 2026
15 checks passed
@fdncred
fdncred deleted the try_catch_error_value branch November 24, 2026 15:44
@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant