-
-
Notifications
You must be signed in to change notification settings - Fork 224
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
Output streams do not emit "end" event if execution fails #517
Comments
FYI, the code I'm trying to make work looks a bit more like this than the examples above: import { execa } from 'execa';
import readline from 'readline';
async function* listFiles( dir ) {
const proc = execa( 'git', [ 'ls-files' ], {
cwd: dir,
stdio: [ 'ignore', 'pipe', null ],
buffer: false
} );
const rl = readline.createInterface( {
input: proc.stdout,
crlfDelay: Infinity,
} );
// We can't allow proc to reject, see https://github.com/sindresorhus/execa/issues/516#issuecomment-1426154012
// So catch the error and save it to rethrow later.
let err;
proc.catch( e => { err = e; } );
// Yield each line of output.
yield* rl;
// If proc rejects, throw the error now.
await proc;
if ( err ) throw err;
} The failure case is if If you have any better ways to handle this code that don't result in reading the whole output of the command into memory, I'd be happy for the suggestion. The rearrangement suggested by @ehmicky in #516 (comment) doesn't seem compatible with use of |
Released in v7.0.0 |
Consider this code (using node 18.13.0 and execa 6.1.0)
Only "stdout closed" is logged, "stdout ended" never happens.
This does not match the behavior of
child_process
:In this case both "stdout ended" and "stdout closed" fire as expected.
The text was updated successfully, but these errors were encountered: