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

Prevent Process Crashing On UnhandledRejection #8593

Closed
Skillz4Killz opened this issue Dec 3, 2020 · 2 comments
Closed

Prevent Process Crashing On UnhandledRejection #8593

Skillz4Killz opened this issue Dec 3, 2020 · 2 comments

Comments

@Skillz4Killz
Copy link

Skillz4Killz commented Dec 3, 2020

Deno will always die on unhandled exceptions / rejections.

I'd like to request the ability to change this for uncaught promises.

I know a lot of people just say hey if this happens it is your fault. Technically your right. But this is reality. And people make mistakes. Production crashing because of a mistake is a serious issue. Especially when it is so easily preventable. But the problem really gets amplified when even if you are perfect, and your code catches everything and everyone, you can still crash if one of your deps forgets. So you can not just rely on yourself being perfect but the entirety of the world needing to be perfect. This in my opinion makes Deno very hard to want to use in production. Processes crashing are not an acceptable solution imo.

Let's take a look at a simple example. Please bare with me here.

image

In this example, what happens is the process crashes. Because the developer of that third party dep forgot to catch something. Now this could be god knows how many deps deep. So the argument that you have to check every line of your deps code isn't really possible realistically. Nor is having to check every single commit of every single dependecy. This just adds on to more reason of why Deno is impossible to use in production.

If this was nested some 10-15 levels deep, we would never be able to debug this and even attempt a fix.

This is all to say that Deno in production is really hard to vouch for. Realistically Deno is only usable in production if you do not use any deps for your projects.


Now for another point of view. Deno is realllllllly hard to use for beginners. A lot of users wanting to use my library are first time developers. This means they are just getting into their very first coding project EVER! I have made it as easy as possible for users like this to be able to get started. They can literally use the strictest TS settings without even needing to know a thing about typing or casting or anything. However, this 1 issue of them forgetting .catch is a serious issue.

Time and time again I have users reporting their processes crashing because they simply forgot to catch something. Not have a training wheel so to speak makes this really difficult. A simple handler to prevent crashes could be soooo useful because I could have this internally built for them so it alerts them of where they are forgetting to catch so that they can fix their code and prevent their processes from crashing.

@nayeemrmn
Copy link
Collaborator

Duplicate of #7013. Discussion of whether or not it should prevent crashes should be taken there, since it's not precluded by the issue title/description.

@josephrocca
Copy link
Contributor

josephrocca commented Oct 10, 2024

Since this is first on Google for "prevent Deno from crashing on error", here's how to do it:

self.addEventListener("error", (event) => {;
  console.error("Uncaught error:", event.error);
  event.preventDefault();
});

self.addEventListener("unhandledrejection", (event) => {
  console.error("Unhandled rejection:", event.reason);
  event.preventDefault();
});

The key part is event.preventDefault() - without that, the script will crash.

(Side note: You can replace self with globalThis if you prefer.)

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

No branches or pull requests

3 participants