-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Fix shape of exceptions rejected by execa()
#276
Conversation
Promise-returning functions should always reject, not throw: https://twitter.com/jaffathecake/status/638659818996269056 |
Yes what the W3C says makes sense. Now the issue in our case is that we are returning both a promise and a At the moment, this requires every consumer to check |
We should always add a |
What about the other properties? If we go that way, it seems like we should set up a mock |
Hmm. I dunno. All I'm certain of is that it should never throw synchronously. |
Yes I agree. I also think that users that use the return value as The only thing I can think of is to merge Actually I think the core issue is us merging two core objects (promise and What do you think of merging |
30cb091
to
4b6f394
Compare
Yeah. That has been bothering me to, in hindsight.
Wish I had done that in the first place...
👍 |
4b6f394
to
6f07979
Compare
execa()
cp.catch(() => {}); | ||
cp.unref(); | ||
cp.on('error', () => {}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test call methods from Promise
, ChildProcess
and EventEmitter
. Just checking they exist is not enough. For example, this
could be incorrect, calling those methods crashes even if they exist.
Fixed. It turns out merging
Basically this code achieves multiple inheritance (even though JavaScript prototype chain only supports single inheritance) by creating a new prototype object merging all prototypes. Another approach would be to use Proxies like this code does. I searched in GitHub for some code that does that and could not find it. The only repositories I can find are either:
Let me know if you want me to create a small module with that logic instead of adding it to |
dba6f5e
to
dda94ac
Compare
execa()
execa()
7eaa83b
to
c61bbef
Compare
👍 Sure, but I think we should ship it for a while first to ensure it correctly solves all our problems. It's easier to extract it later when it's proven to work fine. I would prefer using Proxy as it would be safer. I think the correct term for this is a "mixin". |
c61bbef
to
bb9bf21
Compare
I was thinking that the current PR had the following issue: the way the promise and child process properties are merged differ depending on whether an exception was thrown or not. I re-implemented this PR by simply re-using the "merging" logic already present for the main return value. This turns out to be much clearer and error-prone, with no need for any weird mixin logic or module. As a bonus, the |
Fixes #275.
When some options like
uid
are invalid,child_process.spawn()
throws an exception.At the moment, we catch that exception and return a rejected promise instead. This makes the return value polymorphic: it's probably a
childProcess
, but it might not be.Instead we should keep the error synchronous, i.e. throw an exception just like
child_process.spawn()
does.