pawelgalazka / tasksfile

Minimalistic task runner for node.js
MIT License
350 stars 21 forks source link

Exit code 0 when async run fails #58

Closed pawelgalazka closed 7 years ago

pawelgalazka commented 7 years ago

When run('cmd', {async: true}) fails, process will exit with status code 0. Should be 1.

pawelgalazka commented 7 years ago

If async call run fails without handling promise rejection, process will still finish with exit code 0 (success). Pure node process by default prints unhandled promise rejection warning in that case (unhandled rejection) and exit with code 0, let's keep that behaviour, so this won't be fixed.

fromkeith commented 6 years ago

Possible suggestion / idea for this since it wasn't exactly intuitive to me why runs I had changed from sync to async were still passing on errors...

Can we return a promise, and then have failures cause the exit?

Eg.

export function blah() {
    return run('cmd', {async: true});
}

Since the promise is returned runjs could catch any reject and return status code 1.

Otherwise I'm guessing the suggested workaround is this for every async test?:

export function blah() {
    run('cmd', {async: true})
        .catch((err) => {
             process.exit(1);
        });
}

Thanks!

pawelgalazka commented 6 years ago

Yes, second example is the way to go. Generally runjs inherits nodejs default behaviour when it comes to handling failures for async processes, that means that parent process will still return success code 0 if async process fails. So it's up to developer how to handle async failures so it has full control of it.

markstos commented 5 years ago

Is this behavior changed in taskfile? It can be a nasty surprise to a have a build fail, but have the build continue to deploy stage because the run command returned success instead of failure.