-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
feat(ext/web): Add error events for event listener and timer errors #14159
feat(ext/web): Add error events for event listener and timer errors #14159
Conversation
nayeemrmn
commented
Mar 30, 2022
•
edited
Loading
edited
@lucacasonato @bartlomieju Ready for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Just some minor comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
globalThis.onerror = (e) => { ... }
is not working (but globalThis.addEventListener("error", () => {});
is working), I think we should address it in this PR before landing.
This is very close now @nayeemrmn thanks for working on this, very intricate problem.
That is the strangest thing! I just tried it locally, and indeed! How strange! I will debug this further. It is very strange. |
I have figured it out:
I am not sure if the current code in this PR is susceptible to this issue too. |
Unfortunately, there are issues. Run this 10 times and see it vary in output: addEventListener("foo", () => {
queueMicrotask(() => console.log("queueMicrotask"));
setTimeout(() => console.log("timer"), 0);
throw new Error("bar");
});
console.log(1);
Deno.core.setNextTickCallback(() => console.log("nextTick"));
Deno.core.setHasTickScheduled(true);
dispatchEvent(new CustomEvent("foo"));
console.log(2); Another fun one (#14158): Deno.core.setNextTickCallback(() => {
console.log("nextTick");
Deno.core.setHasTickScheduled(false);
});
Deno.core.setHasTickScheduled(true);
addEventListener("foo", () => {
queueMicrotask(() => console.log("queueMicrotask"));
setTimeout(() => console.log("timer"), 0);
throw new Error("bar");
});
console.log(1);
queueMicrotask(() => {
dispatchEvent(new CustomEvent("foo"));
});
console.log(2); |
@lucacasonato 4e8df5c most likely removes any non-deterministic behaviour that isn't warranted (no IO etc). Without that you sometimes get a single |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple nit picks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nayeemrmn while this now looks good to land, I feel we should discuss it with the rest of the team before actually landing. This PR adds a way to prevent termination of program on uncaught error, which was not possible before (it's similar to adding window.onunhandledrejection
, which is quite controversial). Hope that's okay
This error handling affects calbacks for runtime APIs whose invocations are controlled by the host, when you think about it it's normal to have handlers for stuff like that in comparison to global vanilla error hooks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with everyone, got no objections to land. Thanks @nayeemrmn!
Just one last thing before I land this: can you add an itest case for the scenario I had described above with the flaky output?
@nayeemrmn please draft a commit message |
Added to PR description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great that you managed to get my cleanup working with that biased mode select.
Thanks so much for this, and sorry for the long arduous review!
…14159) - feat: Add handleable error event for even listener errors - feat: Add handleable error event for setTimeout()/setInterval() errors - feat: Add Deno.core.destructureError() - feat: Add Deno.core.terminate() - fix: Don't throw listener errors from dispatchEvent() - fix: Use biased mode when selecting between mod_evaluate() and run_event_loop() results