Skip to content

Commit

Permalink
fix: respect piped PromiseProcess nothrow option (#901)
Browse files Browse the repository at this point in the history
* test: extend pipe rejection suite

* chore: enhance pipe rejection hook

* fix: respect piped Process nothrow option
  • Loading branch information
antongolub committed Sep 17, 2024
1 parent 5038ec5 commit 7a7232c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
}
this._piped = true
if (dest instanceof ProcessPromise) {
const _reject = this._reject
this._reject = function (v) {
_reject(v)
dest._reject(v)
}
this.catch((e) => (dest.isNothrow() ? noop : dest._reject(e)))
dest.stdio('pipe')
dest._prerun = this.run.bind(this)
dest._postrun = () => {
Expand Down
15 changes: 15 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,21 @@ describe('core', () => {
const p3 = await $({ nothrow: true })`echo hello && exit 1`.pipe($`cat`)
assert.equal(p3.exitCode, 0)
assert.equal(p3.stdout.trim(), 'hello')

const p4 = $`exit 1`.pipe($`echo hello`)
try {
await p4
} catch (e) {
assert.equal(e.exitCode, 1)
}

const p5 = $`echo foo && exit 1`
const [r1, r2] = await Promise.allSettled([
p5.pipe($({ nothrow: true })`cat`),
p5.pipe($`cat`),
])
assert.equal(r1.value.exitCode, 0)
assert.equal(r2.reason.exitCode, 1)
})
})

Expand Down

0 comments on commit 7a7232c

Please sign in to comment.