diff --git a/.changeset/lovely-fireants-roll.md b/.changeset/lovely-fireants-roll.md new file mode 100644 index 000000000000..eada691f8632 --- /dev/null +++ b/.changeset/lovely-fireants-roll.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/workflows-shared": patch +--- + +Fixed a bug in local development where fetching a Workflow instance by ID would return a Workflow status, even if that instance did not exist. This only impacted the `get()` method on the Worker bindings. diff --git a/fixtures/import-npm/package-lock.json b/fixtures/import-npm/package-lock.json index 420ebf42c509..11234218d1a9 100644 --- a/fixtures/import-npm/package-lock.json +++ b/fixtures/import-npm/package-lock.json @@ -15,7 +15,7 @@ "dev": true }, "../../packages/wrangler": { - "version": "3.92.0", + "version": "3.95.0", "dev": true, "license": "MIT OR Apache-2.0", "dependencies": { diff --git a/fixtures/workflow/tests/index.test.ts b/fixtures/workflow/tests/index.test.ts index 592feeef7c0d..cb81a544c637 100644 --- a/fixtures/workflow/tests/index.test.ts +++ b/fixtures/workflow/tests/index.test.ts @@ -83,4 +83,15 @@ describe("Workflows", () => { output: [], }); }); + + it("fails getting a workflow without creating it first", async ({ + expect, + }) => { + await expect( + fetchJson(`http://${ip}:${port}/status?workflowName=anotherTest`) + ).resolves.toMatchObject({ + message: "instance.not_found", + name: "Error", + }); + }); }); diff --git a/packages/workflows-shared/src/engine.ts b/packages/workflows-shared/src/engine.ts index 4a80f6cdbdc1..08dd14a0b9b2 100644 --- a/packages/workflows-shared/src/engine.ts +++ b/packages/workflows-shared/src/engine.ts @@ -142,6 +142,10 @@ export class Engine extends DurableObject { _accountId: number, _instanceId: string ): Promise { + if (this.accountId === undefined) { + throw new Error("stub not initialized"); + } + const res = await this.ctx.storage.get(ENGINE_STATUS_KEY); // NOTE(lduarte): if status don't exist, means that engine is running for the first time, so we assume queued