-
-
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
Throw error in sync method - fixes #66 #67
Conversation
Oh, I totally missed |
a8a5684
to
b4031c4
Compare
Odd, this works on my Mac and on Windows but apparently not on Linux... |
The test doesn't seem to be correct. Is there any other way I can make sure something is printed to |
I think you misunderstood. It shouldn't throw when something is outputted on |
b4031c4
to
70ed8e7
Compare
Oh yes, you're totally right! My bad. I fixed the implementation but couldn't come up with a command that had an error object on Windows. I'm really not familiar with that system. Everything I tried just exited with |
Try spawning something that doesn't exist. |
Unfortunately that doesn't give an
|
That sounds like a Node.js bug. The |
Do you mean in the code? Something like this: if (result.error || result.status !== 0) {
throw result.error || new Error(result.stderr);
} |
👍 |
1c790d3
to
8bc78da
Compare
Finally got it working on both Travis and AppVeyor :p. |
@@ -231,6 +231,10 @@ module.exports.sync = (cmd, args, opts) => { | |||
|
|||
const result = childProcess.spawnSync(parsed.cmd, parsed.args, parsed.opts); | |||
|
|||
if (result.error || result.status !== 0) { | |||
throw result.error || new Error(result.stdout === '' ? result.stderr : result.stdout); |
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.
Wrap it in parens for clarity:
throw (result.error || new Error(result.stdout === '' ? result.stderr : result.stdout));
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.
Would it make sense to switch the stdout/stderr
check to something like this
new Error(result.stderr === '' ? result.stdout : result.stderr);
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.
Yes, actually, that would make sense.
@@ -95,6 +95,8 @@ Same options as [`child_process.execFileSync`](https://nodejs.org/api/child_proc | |||
|
|||
Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options). | |||
|
|||
This method throws an `Error` if something is written to `stderr`. |
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 needs to reflect the actual code.
Can this be merged now? I would love to have it in ❤️ |
It's waiting on #67 (comment) |
@sindresorhus I fixed that. Forgot to notify you. |
Cool. Thanks Sam :) |
You're welcome! And thank you for merging 🎉 |
This should fix #66 by throwing an
Error
object if something is written tostderr
. Also added a test for this.