Commit 7a7232c
Changed files (2)
src
test
src/core.ts
@@ -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 = () => {
test/core.test.js
@@ -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)
})
})