cloudflare / cloudflare/workerd

fetch() network failures reject with Error instead of TypeError

Open
#7,195 0 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

On workerd `1.20260828.1`:

```js
try {
await fetch("http://127.0.0.1:1/");
} catch (error) {
console.log(error.name, error instanceof TypeError, error.message);
// Error false Network connection lost.
}
```

The [Fetch standard](https://fetch.spec.whatwg.org/#dom-global-fetch) requires network errors to reject with a `TypeError`.

workerd currently maps all `DISCONNECTED` exceptions to a plain `Error` [here](https://github.com/cloudflare/workerd/blob/29ee6949f48c3bd97b5bec542777f53ef42a3397/src/workerd/jsg/util.c%2B%2B#L322-L336).

Related:
- sindresorhus/is-network-error#13
- [Workers error docs](https://developers.cloudflare.com/workers/observability/errors/#runtime-errors) don't include the trailing `.`.

Contributor guide

Open the contributing guide

Research direction

Start in src/workerd/jsg/util.c++ at the linked exception-mapping code around lines 322-336, then trace the fetch call that produces the disconnected network failure. Confirm the existing behavior with the provided workerd fetch example and inspect nearby tests if present. Done means a network failure rejects with a TypeError and reports the expected error name and message.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, javascript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.