Giter Site home page Giter Site logo

Comments (6)

jedwards1211 avatar jedwards1211 commented on May 30, 2024 2

@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.

vjpr avatar vjpr commented on May 30, 2024

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.

vjpr avatar vjpr commented on May 30, 2024

.catch(e => e) was what I was needing. Thanks!

However, I should also attach these properties

Would be good.

from promisify-child-process.

ranasaria avatar ranasaria commented on May 30, 2024

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.

jedwards1211 avatar jedwards1211 commented on May 30, 2024

@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.

mattalexx avatar mattalexx commented on May 30, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.