Comments (7)
That section says:
The child process promise will only resolve if the process exits with a code of 0. If it exits with any other code, is killed by a signal, or emits an 'error' event, the promise will reject.
It's hard for me to tell how you interpreted that section...'error'
events are emitted if there was some problem even spawning the process, not if it exited or got killed or outputted to stderr
. The process can write to stderr
even if it exits with 0 (and the promise resolves), or it could exit 1 or get killed without writing anything to stderr
. So stderr
output doesn't necessarily indicate an error.
However, you have a point, it is tempting to make the promise resolve to just stdout
(string or Buffer) like how execSync
returns only stdout
. I hadn't considered this; Node's async exec
callback receives both stdout
and stderr
as arguments so there's sort of a mismatch. Since this would be a breaking change though and could cause disruption, I guess I should figure out a way to have users of this package vote on it.
from promisify-child-process.
I understand your premise about stderr
being populated even child_process
exits quietly. but I think, from node docs, stderr
will always be filled when an error is generated. Although you are right, it would be tough to decide what to do if spawning fails.
You make a good point about APIs breaking changes. But I would have it sooner than later as it simplifies coding design a whole lot simpler. :)
from promisify-child-process.
Throwing my two cents here...
I agree with @jedwards1211 that a child process can write to stdout
, stderr
, both, or neither. The exit code is the most reliable indicator if the child process actually had an error.
A convention with shell scripts is to log information to stderr
while returning the actual result for piping to other commands to stdout
. As long as the script exits with code 0 then all good. Any other exit code indicates an error and then it's up to the documentation/api of the script being executed on what stdout
and stderr
might even mean.
For CI/CD scripts, I use stderr
extensively for logging details for troubleshooting and showing progress but only write to stdout
if the script is expected to return a value. I would not want my script to be considered failed or rejected because I wrote to stderr
since my exit code was 0 (success).
from promisify-child-process.
Yeah don't worry, I would never make it reject just because stderr
gets written to. As far as the other aspect of what OP was saying though, would you consider it more convenient if await exec(...)
resolved to just the stdout? I guess if I made that change I could add an instance method you can await to get both stdout and stderr.
from promisify-child-process.
from node docs, stderr will always be filled when an error is generated
Can you give me a link to where you read about this?
I'm assuming you read that node will output to stderr
if there is an uncaught exception or unhandled promise rejection. This doesn't imply that anything that could cause the process to exit with a nonzero code is guaranteed to write to stderr
: a program could catch an error and process.exit(1)
without writing to stderr
, and the exit code of 1 would still mean something went wrong.
from promisify-child-process.
Yeah don't worry, I would never make it reject just because
stderr
gets written to.
👍
As far as the other aspect of what OP was saying though, would you consider it more convenient if
await exec(...)
resolved to just the stdout? I guess if I made that change I could add an instance method you can await to get both stdout and stderr.
Personally, I think the API is fine how you have it. Using destructuring I can grab just stdout, stderr, or the whole response in one statement.
const response = await exec(...);
const { stdout, stderr } = await exec(...);
const { stdout } = await exec(...);
from promisify-child-process.
Right, it would basically save a few keystrokes. I am about saving keystrokes, but... another thing is it's possible to use a wrapper function to return stdout directly (maybe I should export one).
from promisify-child-process.
Related Issues (20)
- [typescript] PromisifyChildProcessOptions missing properties HOT 1
- Unnecessarily large install size HOT 7
- add .finally delegate method HOT 1
- revisit close vs. exit HOT 1
- use byte length, not character length to determine if maxBuffer is exceeded HOT 1
- index.mjs not included in npm package HOT 2
- Action Required: Fix Renovate Configuration
- Example for fork HOT 2
- Time consuming process waits indefinitely HOT 9
- Can this work for browser HOT 5
- NPM scripts do not set environment variable in cross-platform way HOT 1
- Convert Project to TypeScript
- The automated release is failing 🚨 HOT 1
- Add TypeScript typings HOT 4
- Don't capture console output by default in spawn (breaking change) HOT 1
- `child.stdout` not available after `spawn` HOT 3
- Dependency deprecation warning: travis-deploy-once (npm)
- Option to not throw on non-zero exit code HOT 6
- Missing typescript definition file in v3.1.2 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from promisify-child-process.