Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error instead of using process.exit #20

Open
aoberoi opened this issue May 14, 2019 · 2 comments · May be fixed by #30
Open

Throw an error instead of using process.exit #20

aoberoi opened this issue May 14, 2019 · 2 comments · May be fixed by #30

Comments

@aoberoi
Copy link

aoberoi commented May 14, 2019

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.

@aoberoi
Copy link
Author

aoberoi commented May 14, 2019

Another advantage: this would also give users of this package to catch the thrown error, in cases where they want some behavior other than exiting.

@BryanTorreblanca00 BryanTorreblanca00 linked a pull request Oct 3, 2022 that will close this issue
@NITHISH-1609
Copy link

We can use this to achieve!

process.on("uncaughtException", (err) => {
  console.error("Uncaught Exception:", err);
  // Don't call process.exit() to keep the server running
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants