cloudflare / cloudflare/workerd

`DispatchNamespace.get` does not throw on missing worker as documented

Open
#5,263 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

### What versions & operating system are you using?

System:
OS: macOS 26.0.1
CPU: (10) arm64 Apple M1 Max
Memory: 666.42 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.17.1 - /Users/timkelty/.nvm/versions/node/v22.17.1/bin/node
npm: 10.9.2 - /Users/timkelty/.nvm/versions/node/v22.17.1/bin/npm
pnpm: 8.15.4 - /opt/homebrew/bin/pnpm
npmPackages:
@cloudflare/vitest-pool-workers: ^0.8.19 => 0.8.71
wrangler: ^4.42.1 => 4.42.1

### Please provide a link to a minimal reproduction

_No response_

### Describe the Bug

The generated type definition looks like this:

```
interface DispatchNamespace {
/**
* @param name Name of the Worker script.
* @param args Arguments to Worker script.
* @param options Options for Dynamic Dispatch invocation.
* @returns A Fetcher object that allows you to send requests to the Worker script.
* @throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.
*/
get(name: string, args?: {
[key: string]: any;
}, options?: DynamicDispatchOptions): Fetcher;
}
```

However, the `@throws If the Worker script does not exist in this dispatch namespace, an error will be thrown.` appears to be inaccurate.

Given a `hello-world` in the matching namespace, this dispatch worker will throw with a "worker not found" exception, as is not thrown until `fetch` is called:

```
export default {
async fetch(request: Request, env: Env): Promise {
let worker;

try {
worker = env.DISPATCHER.get('does-not-exist');
} catch (cause) {
worker = env.DISPATCHER.get('hello-world');
}

return await worker.fetch(request);
},
} satisfies ExportedHandler;
```

With the behavior as-is, you're forced to wrap the fetch in a try/catch, at which point you can't distinguish between a missing worker and an actual exception thrown from the fetch.

Feels like a bug, and it should actually work how it is documented.

### Please provide any relevant error logs

_No response_

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.