Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Awkward behavior on error with pipe #640

@mighty1231

Description

@mighty1231

single exit 1 process - throws error

exit 1 process with piped - does not throw error

Is it intended behavior?

async function checkPipe() {
  try {
    await $`exit 1`.pipe($`echo hello`);
    console.log("not error at first");
  } catch (e) {
    console.log("it does not reach here (1)");
  }

  try {
    await $`exit 1`;
    console.log("it does not reach here (2)");
  } catch (e) {
    console.log("error catched!");
  }
}

await checkPipe();

Expected Stdout

$ exit 1
$ echo hello
hello
it does not reach here (1)
error catched!

Actual Behavior

$ exit 1
$ echo hello
hello
not error at first
file:///wd/temp.ts:106
    await $`exit 1`.pipe($`echo hello`);
           ^
ProcessOutput [Error]: 
    at checkPipe (file:///wd/temp.ts:106:12)
    exit code: 1
    at ChildProcess.<anonymous> (file:///wd/node_modules/zx/build/core.js:146:26)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess.emit (node:domain:489:12)
    at maybeClose (node:internal/child_process:1100:16)
    at Socket.<anonymous> (node:internal/child_process:458:11)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at Pipe.<anonymous> (node:net:301:12)
    at Pipe.callbackTrampoline (node:internal/async_hooks:130:17) {
  _code: 1,
  _signal: null,
  _stdout: '',
  _stderr: '',
  _combined: ''
}

Specifications

  • Version: 7.2.2
  • Platform: Linux (Ubuntu 18.04)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions