Skip to content

Throw an error instead of using process.exit #20

Open
@aoberoi

Description

@aoberoi

I'd like to suggest that instead of calling process.exit(), we throw an Error.

As described in node's documentation for process.exit(), using this method is problematic because it disrupts all asynchronous work in progress. The documentation recommends using an error instead:

If it is necessary to terminate the Node.js process due to an error condition, throwing an uncaught error and allowing the process to terminate accordingly is safer than calling process.exit().

One concern with making this change would be preserving the functionality of opts.exitCode. I believe we can set process.exitCode right before throwing the error, and it should preserve the intended behavior.

If the maintainers are happy with this idea, I can contribute the change in a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions