Skip to content

pipefail: avoid try outputs value when catch exists, avoid finally runs twice, avoid finally funs before try finish.#17764

Merged
WindSoilder merged 4 commits intonushell:mainfrom
WindSoilder:push-mrwmkszplwlt
Mar 12, 2026
Merged

pipefail: avoid try outputs value when catch exists, avoid finally runs twice, avoid finally funs before try finish.#17764
WindSoilder merged 4 commits intonushell:mainfrom
WindSoilder:push-mrwmkszplwlt

Conversation

@WindSoilder
Copy link
Copy Markdown
Contributor

@WindSoilder WindSoilder commented Mar 10, 2026

Fixes: #17730
Fixes: #17715
Fixes: #17567

This pr is going to do the following things in order to fix these issues at once:

  1. Making Instruction::Collect ignore pipefail checking, so anything invoves collect won't check pipefail, for example: let, argument passing, binary operation, match expression
  2. Restrict try block from streaming if it contains catch block or finally block. This is done by adding a new Instruction::CollectFailuable after relative block. It is similar to Instruction::Collect, except it checks pipefail.
  3. Before running finally block, evaluate PopFinallyRun instruction first, this avoids duplicate finally block runs.

Release notes summary - What our users need to know

finally block won't run twice if error produced in finally block

> try {
} finally {
    print "inside finally"
    error make
}

It prints "inside finally" once.

finally block won't run before try/catch finished

try {
    ^ping -n 3 127.0.0.1   # or `^ping -c 3 127.0.0.1` on Linux/macOS
} finally {
    print "finally ran"
}

Finally won't run before try finished.
NOTES ABOUT STREAMING:
try won't streaming if catch or finally exists.
catch won't streaming if finally exists

let ignores pipefail checking

> sh -c "echo 'hello\nworld' && false" | lines | let x

The variable x will be assigned.

Try doesn't produce output if it has an error

> try { bash -c 'exit 1' | is-empty } catch { 'result-on-catch' }
result-on-catch

It returns result-on-catch, and redundant true won't be outputed.

Tasks after submitting

NaN

@WindSoilder WindSoilder added the notes:fixes Include the release notes summary in the "Bug fixes" section label Mar 10, 2026
@WindSoilder WindSoilder merged commit 7f69d75 into nushell:main Mar 12, 2026
16 checks passed
@github-actions github-actions bot added this to the v0.112.0 milestone Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Include the release notes summary in the "Bug fixes" section

Projects

None yet

2 participants