Fix Queues docs code examples & types#28192
Conversation
…ractices - Fix MessageSendRequest type to match @cloudflare/workers-types (contentType and delaySeconds are direct properties, not nested under options) - Add readonly modifier to MessageBatch.messages in type definitions - Use satisfies ExportedHandler<Env> pattern consistently across all examples - Replace let with const where values are not reassigned - Fix Error type issues: native Error objects are not structured-clone serializable, use serializable ErrorMessage interface instead - Add proper error type narrowing in catch blocks (instanceof Error) - Remove e: any catch annotations in favor of proper type narrowing - Fix missing return statements in fetch handlers - Fix Durable Objects example: use DurableObject base class instead of deprecated implements DurableObject pattern, add missing closing brace - Replace Queue<any> with properly typed Queue<Message> throughout - Use interface instead of type for Env declarations consistently - Fix sendBatch example that unnecessarily JSON.stringified message bodies - Update AI skill reference to match corrected MessageSendRequest type
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
|
/bonk great work, Bonk. thoroughly re-review all code changes for validity, just like @threepointone would. |
|
Now I have everything to do a thorough review. Let me compile my findings. Here is my thorough review of all code changes in this PR, validated against the actual Verified Correct Changes1.
|
|
/bonk fix the remaining issues, including making the "how queues works" snippet more clearer/complete vs. implicit |
|
APIError: |
|
Bonk workflow failed. Check the logs for details. |
|
/bonk try again, and review the failed run + explain why: https://github.com/cloudflare/cloudflare-docs/actions/runs/21803944799/job/62904040532 |
…s in how-queues-works
|
Done. Here's what happened and what I fixed: Why the previous run failedThe previous run (21803944799) crashed due to a transient Cloudflare AI Gateway error (error code 2005: What I fixedAll three issues in
|
|
Bonk workflow was cancelled. |
…tion - Reverts all changes to skills/cloudflare/references/queues/api.md (out of scope) - Adds missing options?: QueueSendBatchOptions parameter to the sendBatch description text in javascript-apis.mdx (was already in the interface definition but missing from the prose description)
|
Done. Here's what I did: 1. Reverted 2. Reviewed all changes against
3. Fixed the |
Here's a summary of all the changes made across 10 files:
Changes Summary
Type Correctness Fixes
javascript-apis.mdx(API reference)MessageSendRequestinterface:contentTypeanddelaySecondsare direct properties on the interface per@cloudflare/workers-types, not nested under anoptionsfieldreadonlymodifier toMessageBatch.messagesto match the actual type definitionsendBatchexample that unnecessarily calledJSON.stringify()on message bodies (the body should be the raw value)Array<any>toArray<unknown>in the batch send helpersend-errors-to-r2.mdxErrorobjects are NOT structured-clone serializable and can't be sent to a Queue. ReplacedQueue<Error>with a serializableErrorMessageinterface ({ message: string; stack?: string })instanceof Errorin catch blocksdoRequestreturn type fromPromise<Response>toResponse(it returns synchronously)how-queues-works.mdxMessageBatch<Error>generic parameter (confusing/wrong -Erroris not a queue message type)return new Response("Sent!")in the first producer exampleResponse.json({"msg": e})(can't serialize Error to JSON) to propere instanceof Errornarrowinguse-queues-with-durable-objects.mdx}brace for the classimplements DurableObjectpattern toextends DurableObject<Env>base classthis.state.idtothis.ctx.id(new DurableObject base class API)DurableObjectNamespace<YourDurableObject>genericBest Practices / Consistency Fixes (all files)
satisfies ExportedHandler<Env>: Applied consistently to all 22export defaultblocks across all files (was missing from many or used explicit type annotations on handler params instead)constoverlet: Replacedletwithconstfor variables that are never reassigned (e.g.,log,url,userIdParam)interfaceovertype: Usedinterface Envconsistently instead oftype EnvironmentQueue<any>removed: Replaced with properly typedQueue<Message>in tutorialse: anycatch removed: Replaced withinstanceof Errortype narrowingsatisfies(async fetch(req, env, ctx)) instead of explicit annotations (async fetch(req: Request, env: Env))ctxparameter: All handler signatures now include thectxparameter consistentlyFiles Changed
src/content/docs/queues/configuration/javascript-apis.mdxsrc/content/docs/queues/configuration/batching-retries.mdxsrc/content/docs/queues/get-started.mdxsrc/content/docs/queues/reference/how-queues-works.mdxsrc/content/docs/queues/examples/send-errors-to-r2.mdxsrc/content/docs/queues/examples/use-queues-with-durable-objects.mdxsrc/content/docs/queues/examples/publish-to-a-queue-via-workers.mdxsrc/content/docs/queues/tutorials/handle-rate-limits/index.mdxsrc/content/docs/queues/tutorials/web-crawler-with-browser-rendering/index.mdxskills/cloudflare/references/queues/api.mdCloses #28191
github run