Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/dispatch-namespace-not-found.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@cloudflare/deploy-helpers": patch
"wrangler": patch
---

Fix first deploys of a Worker to a dispatch namespace failing with `This Worker does not exist on your account. [code: 10007]`

Before uploading to a dispatch namespace, Wrangler checks whether the Worker already exists. The Cloudflare API now reports a missing Worker in a dispatch namespace with code `10007`, which Wrangler treated as a failure instead of a new Worker. Deploying a new Worker with `wrangler deploy --dispatch-namespace` works again.
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,10 @@ export async function preUploadApiChecks(
`/accounts/${accountId}/workers/dispatch/namespaces/${props.dispatchNamespace}/scripts/${name}`
);
} catch (e) {
// The API has reported a missing dispatch namespace script with both codes
if (
typeof e === "object" &&
e !== null &&
"code" in e &&
e.code === 10092
isWorkerNotFoundError(e) ||
(typeof e === "object" && e !== null && "code" in e && e.code === 10092)
Comment thread
NuroDev marked this conversation as resolved.
Resolved
) {
workerExists = false;
} else {
Expand Down
39 changes: 39 additions & 0 deletions packages/wrangler/src/__tests__/deploy/environments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,45 @@ describe("deploy", () => {
`);
});

it.for([
{ code: 10092, message: "workers.api.error.environment_not_found" },
{ code: 10007, message: "This Worker does not exist on your account." },
{ code: 10090, message: "workers.api.error.service_not_found" },
])(
"should upload a new Worker to dispatch namespace when the API reports it missing with code $code",
async ({ code, message }, { expect }) => {
writeWranglerConfig();
fs.writeFileSync(
"index.js",
`export default { fetch() { return new Response("Hello, World!"); } }`
);
mockUploadWorkerRequest({
expectedMainModule: "index.js",
expectedDispatchNamespace: "test-dispatch-namespace",
});
msw.use(
http.get(
"*/accounts/:accountId/workers/dispatch/namespaces/:dispatchNamespace/scripts/:scriptName",
() =>
HttpResponse.json({
success: false,
errors: [{ code, message }],
messages: [],
result: null,
})
)
);

await runWrangler(
"deploy --dispatch-namespace test-dispatch-namespace index.js"
);
expect(std.out).toContain("Uploaded test-name (TIMINGS)");
expect(std.out).toContain(
"Dispatch Namespace: test-dispatch-namespace"
);
}
);

it("should warn when crons are configured alongside --dispatch-namespace", async ({
expect,
}) => {
Expand Down
Loading