-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
Impossible to trap errors from child process #144
Comments
Some investigation: Given an environment with no cmd (as described above) edit index.js (https://github.com/sindresorhus/open/blob/master/index.js) line 131 and onwards:
Then import index.js in another file and run:
This will print:
This means that the subprocess error is emitted before the caller gets the process. This means that we will not be able to listen for the error event in the caller. This also means that we cannot throw an error in the event callback in open, as this will fire too late. One possibility is to force a wait, this seems to work. The problem here is that when things work out, we will be waiting for the process to exit for a loooong time.. One (hacky?) solution is to always "wait", but when not wait is set, use a setTimeout to resolve if things does not go wrong after a (short) while, someting like this seems to wotk
|
Solves (?) sindresorhus#144. using setTimeout is perhaps a bit buggy, but this seems to fix the issue
Some other solutions:
|
Option 1 is rather straight-forward (I think):
|
Howdy! This is an explanation for #56
For various reasons, cmd isn't in always in the system path on windows. This makes calls to spawn fail with an
ENOENT
.This wouldn't be an issue on its own, except that
open
gives no way to trap that error. Because theopen
function is async, by the time the promise resolves and we have access to a ChildProcess that we can add an error event listener to, the error event has already fired and bubbled up to the top level, crashing the program with anENOENT
.Repro for windows:
index.js
to some non-existent binary like "abcmd"Full repro available here.
The text was updated successfully, but these errors were encountered: