types: clarify DispatchNamespace.get does not throw on missing worker (fixes #5263)#6765
types: clarify DispatchNamespace.get does not throw on missing worker (fixes #5263)#6765LeSingh1 wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
petebacondarwin
left a comment
There was a problem hiding this comment.
LGTM as a docs change
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 cloudflare#5263
Signed-off-by: LeSingh1 <sshaurya914@gmail.com>
3910aa5 to
5178de8
Compare
Merging this PR will degrade performance by 12.74%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | Encode_ASCII_32[TextEncoder][0/0/32] |
2.8 ms | 3.2 ms | -12.74% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing LeSingh1:docs-dispatch-namespace-throws-on-fetch (5178de8) with main (6b8b117)
Footnotes
-
129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Summary
The JSDoc for
DispatchNamespace.getintypes/defines/wfp.d.tsclaimed:In practice,
getalways returns aFetcher; the "Worker not found" error is only surfaced when the returned Fetcher'sfetch()is invoked. The reporter demonstrated this with a clear repro in #5263. The dynamic dispatch example in the Cloudflare docs already documents the workaround (e.message.startsWith('Worker not found')inside thefetch()try/catch), which confirms the runtime behavior is intentional — only the JSDoc was misleading.Fix
Replaced the inaccurate
@throwsline with a note describing the actual behavior and where the error surfaces. This is a docs-only change; no runtime behavior is affected.Updated:
types/defines/wfp.d.ts— the source definition (the file the issue links to is generated from this).types/generated-snapshot/{latest,experimental}/index.{ts,d.ts}so the snapshot check stays green. (I do not have a Bazel build environment to regenerate them viabazel build //types:types; if reviewers prefer the snapshots be regenerated, please tell me and I'll redo locally.)Verification
grep -rn "@throws If the Worker script does not exist" types/returns no remaining matches after the patch.Issue
Fixes #5263