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

Report queueMicrotask errors to the error event #2597

Merged
merged 1 commit into from
Aug 24, 2024

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented Aug 23, 2024

Per the queueMicrotask(...) spec... https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#microtask-queuing

globalThis.addEventListener('error', (event) => {
  console.log(event.error);
  return true;
})

queueMicrotask(() => {
  throw new Error('sync error throw in microtask');
});

The 'error' event should preserve async context in case the queueMicrotask originates from within a request:

const als = new AsyncLocalStorage();
addEventListener('error', (event) => {
  console.log(als.getStore());
});

export default {
  fetch() {
    als.run(123, () => {
      queueMicrotask(() => {
        throw new Error('boom');
      });
    });
  }
}

// microtasks automatically, we can remove this workaround.
KJ_IF_SOME(context, jsg::AsyncContextFrame::current(js)) {
task = context.wrap(js, task);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For review: Just noting... we no longer need to manually propagate the async context to EnqueueMicrotask() since v8 finally closed that gap recently. Just hadn't gotten around to removing this previously.

```js

globalThis.addEventListener('error', (event) => {
  console.log(event.error);
  return true;
})

queueMicrotask(() => {
  throw new Error('sync error throw in microtask');
});
```
Copy link
Member

@anonrig anonrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comment on lines +696 to +698
for (int n = 0; n < args.Length(); n++) {
argv.add(args[n]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argv.addAll(args);
// argv.addAll(args.begin(), args.end());

Copy link
Member Author

@jasnell jasnell Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't think that works. args here does not have a begin() or end() as far as I'm aware.

@jasnell jasnell merged commit 537c806 into main Aug 24, 2024
10 checks passed
@jasnell jasnell deleted the jsnell/queuemicrotask-reporterror branch August 24, 2024 00:02
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 this pull request may close these issues.

2 participants