Repository navigation
Run catch when try is piped into ignore, complete, save or tee - #19647
Merged
Merged
Conversation
…`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.
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
Since 0.114.0,
tryskipscatchwhen it's piped intoignore,complete,saveorteeand the error comes from the last command in its block.finallystill 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 atry. Call it asmy-command | ignoreand itscatchnever runs.#18306 made a command return its error as a value when its stderr goes to a separate pipe. That lets
ignore --stderrdecide what to do with the error. All four commands above ask for that separate pipe, and the last command in atryblock inherits the redirection of whatever follows thetry. So the error turned into a value, passed throughtrywithout reachingcatch, 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.trynow raises an error value that reaches the end of its block, or the end ofcatchbeforefinally. The handlers run the same as they do without the pipe. When onlyfinallyhandles the error,finallygets the error record. Then the error goes on to the next command as a value, the same as withoutfinally, soignore --stderrstill consumes it.User-facing changes (Release notes)
tryskippingcatchwhen it's piped intoignore,complete,saveortee, including through a custom command that ends in atry. In the same casefinallynow gets the error record instead of the raw error. This was a regression in 0.114.0.try { ... } catch { 'fallback' } | ignore --stderrnow passes onfallbackinstead of consuming the error, andtry { exit 3 } | ignore --stderrnow exits.Additional notes