cloudflare / cloudflare/workerd

RFE: Log unhandled promise rejections

Open
#412 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

When an unhandled promise rejection occurs in a browser, it shows up as an error log line in dev tools. However, when these rejections occur in workers, they do not appear anywhere. This can be problematic when trying to debug issues with worker code.

It would be helpful if these rejections could show up in the log and logpush like they do in a browser. Currently, I need to manually add an event listener for `unhandledrejection` before any other code is executed and make sure that it is only added once. This can be cumbersome, especially when working with more complex worker code.

I believe it would be beneficial if workers could handle unhandled promise rejections in the same way that browsers do, as this would make it easier to catch errors and debug worker code.

As a simple test case, I created the following code snippet:

```js
export default {
async fetch(request) {
Promise.reject(new Error('I was rejected'));
return new Response('OK');
}
};

```

I would expect to find the string `'I was rejected'` in my logpush logs, but as mentioned earlier, this is not currently the case.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.