From 3910aa5533c07b9049d21281fa851f95258c982b Mon Sep 17 00:00:00 2001 From: LeSingh1 Date: Sun, 17 May 2026 19:04:38 -0700 Subject: [PATCH] types: clarify DispatchNamespace.get does not throw on missing worker The JSDoc for `DispatchNamespace.get` claimed an error would be thrown when the named Worker script does not exist in the dispatch namespace. In practice, `get` always returns a `Fetcher`; the "Worker not found" error is only surfaced when the returned Fetcher's `fetch()` is invoked. A user-facing example on developers.cloudflare.com already documents the workaround (`e.message.startsWith('Worker not found')` inside the fetch try/catch), so the runtime behavior is intentional -- only the JSDoc was misleading. Replace the inaccurate `@throws` line with a note describing the actual behavior and where the error surfaces. Updates `types/defines/wfp.d.ts` plus the corresponding latest/experimental generated snapshots so the docs stay in sync. Fixes #5263 Signed-off-by: LeSingh1 --- types/defines/wfp.d.ts | 6 +++++- types/generated-snapshot/experimental/index.d.ts | 6 +++++- types/generated-snapshot/experimental/index.ts | 6 +++++- types/generated-snapshot/latest/index.d.ts | 6 +++++- types/generated-snapshot/latest/index.ts | 6 +++++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/types/defines/wfp.d.ts b/types/defines/wfp.d.ts index 68468261f2f..75b2c7e225f 100644 --- a/types/defines/wfp.d.ts +++ b/types/defines/wfp.d.ts @@ -26,7 +26,11 @@ interface DispatchNamespace { * @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. + * + * Note: `get` does not validate that the named Worker script exists in the + * dispatch namespace. It always returns a Fetcher; if the script is missing, + * the resulting "Worker not found" error is surfaced when `fetch()` is + * invoked on the returned Fetcher. */ get(name: string, args?: {[key: string]: any}, options?: DynamicDispatchOptions ): Fetcher; } diff --git a/types/generated-snapshot/experimental/index.d.ts b/types/generated-snapshot/experimental/index.d.ts index a24240d382e..38e66113b77 100755 --- a/types/generated-snapshot/experimental/index.d.ts +++ b/types/generated-snapshot/experimental/index.d.ts @@ -15848,7 +15848,11 @@ interface DispatchNamespace { * @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. + * + * Note: `get` does not validate that the named Worker script exists in the + * dispatch namespace. It always returns a Fetcher; if the script is missing, + * the resulting "Worker not found" error is surfaced when `fetch()` is + * invoked on the returned Fetcher. */ get( name: string, diff --git a/types/generated-snapshot/experimental/index.ts b/types/generated-snapshot/experimental/index.ts index a221881cb04..ac3c9f0e9b7 100755 --- a/types/generated-snapshot/experimental/index.ts +++ b/types/generated-snapshot/experimental/index.ts @@ -15809,7 +15809,11 @@ export interface DispatchNamespace { * @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. + * + * Note: `get` does not validate that the named Worker script exists in the + * dispatch namespace. It always returns a Fetcher; if the script is missing, + * the resulting "Worker not found" error is surfaced when `fetch()` is + * invoked on the returned Fetcher. */ get( name: string, diff --git a/types/generated-snapshot/latest/index.d.ts b/types/generated-snapshot/latest/index.d.ts index 989b8c88bbf..3ff39f0a77e 100755 --- a/types/generated-snapshot/latest/index.d.ts +++ b/types/generated-snapshot/latest/index.d.ts @@ -15180,7 +15180,11 @@ interface DispatchNamespace { * @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. + * + * Note: `get` does not validate that the named Worker script exists in the + * dispatch namespace. It always returns a Fetcher; if the script is missing, + * the resulting "Worker not found" error is surfaced when `fetch()` is + * invoked on the returned Fetcher. */ get( name: string, diff --git a/types/generated-snapshot/latest/index.ts b/types/generated-snapshot/latest/index.ts index ed0c2cd4c74..119a66a8fb7 100755 --- a/types/generated-snapshot/latest/index.ts +++ b/types/generated-snapshot/latest/index.ts @@ -15141,7 +15141,11 @@ export interface DispatchNamespace { * @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. + * + * Note: `get` does not validate that the named Worker script exists in the + * dispatch namespace. It always returns a Fetcher; if the script is missing, + * the resulting "Worker not found" error is surfaced when `fetch()` is + * invoked on the returned Fetcher. */ get( name: string,