Comments (6)
@vjpr Yeah I need to improve the docs, thanks for pointing this out. If it throws, you can read error.code
, error.signal
, just like child_process.exec
. This lib also attaches stdout
and stderr
to the error it throws. Instead of wrapping in try
/catch
, you can add .catch(e => e)
(even within an async function) and then read code
, signal
, stdout
, and stderr
on the result regardless of whether it threw or not.
However, I should also attach these properties in the case the ChildProcess
emitted an error
...
And I should add code
/signal
to the result if it succeeded as well.
from promisify-child-process.
The default behavior is fine as it matches Node's promisify behaviour: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback
If this method is invoked as its util.promisify()ed version, it returns a Promise for an Object with stdout and stderr properties. In case of an error (including any error resulting in an exit code other than 0), a rejected promise is returned, with the same error object given in the callback, but with an additional two properties stdout and stderr.
Accessing the code
from the result should be removed from the docs, or an example should be added showing the need to try/catch on failure.
from promisify-child-process.
.catch(e => e)
was what I was needing. Thanks!
However, I should also attach these properties
Would be good.
from promisify-child-process.
would the following code work to capture exit code in all success and failure cases?
child.on('exit', (code) => {
doWhateverWithCode(code);
});
from promisify-child-process.
@ranasaria Well if the process exits because of a signal, code
will be undefined, instead the signal
argument will be defined. Otherwise that should work.
from promisify-child-process.
@vjpr Yeah I need to improve the docs, thanks for pointing this out.
I read your docs, noticed that you were returning the exit code, and assumed that I would not need to catch an exception if the child process exited non-zero. I would recommend changing either the behavior or the docs.
Thanks for the lib 👍
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)
- Missing typescript definition file in v3.1.2 HOT 3
- How to get rejected promise instead of output.stderr HOT 7
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.