-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Awkward behavior on error with pipe #640
Comments
@antongolub what do you think is a proper behavior here? |
Well, the queue is pretty clear:
I think, this is fine. Just imagine a case, when some piped process awaits for the input and meets |
@antonmedv Is it fine that none of the log executed after the second $ call? neither these logs shown
Let's rewrite the issue in more detailed way with 3 examples. case 1 (normal)just a single $ statement handles exception in nice way import { $ } from "zx/core";
async function checkPipe() {
try {
await $`exit 1`;
console.log("it does not reach here (2)");
} catch (e) {
console.log("error catched!");
}
}
await checkPipe(); result $ node abc.mjs 2>/dev/null
error catched! case 2 (weird)import { $ } from "zx/core";
async function checkPipe() {
// run a piped process that fails
try {
await $`exit 1`.pipe($`echo hello`);
} catch (e) {
// do nothing
}
console.log('no matter for intermediate log');
// same as case 1 below
try {
await $`exit 1`;
console.log("it does not reach here (2)");
} catch (e) {
console.log("error catched!");
}
}
await checkPipe(); result $ node abc.mjs 2>/dev/null
no matter for intermediate log where does the log case 3How about pipe in bash instead zx's pipe? import { $ } from "zx/core";
async function checkPipe() {
try {
// bash's pipe
await $`exit 1 | echo hello`;
} catch (e) {
// do nothing
}
console.log('no matter for intermediate log');
try {
await $`exit 1`;
console.log("it does not reach here (2)");
} catch (e) {
console.log("error catched!");
}
}
await checkPipe(); result $ node abc.mjs 2>/dev/null
no matter for intermediate log
error catched! Hello error catched! Specification
|
single
exit 1
process - throws errorexit 1
process with piped - does not throw errorIs it intended behavior?
Expected Stdout
Actual Behavior
Specifications
The text was updated successfully, but these errors were encountered: