-
Notifications
You must be signed in to change notification settings - Fork 670
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: provide proper error message for missing DOs (#4337)
- Loading branch information
Showing
10 changed files
with
192 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
Improve the error message when a script isn't exported a Durable Object class | ||
|
||
Previously, wrangler would error with a message like `Uncaught TypeError: Class extends value undefined is not a constructor or null`. This improves that messaging to be more understandable to users. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "do-worker-app", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "", | ||
"license": "ISC", | ||
"author": "", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"dev": "wrangler deploy --dry-run", | ||
"test": "npx vitest run", | ||
"test:ci": "npx vitest run", | ||
"test:watch": "npx vitest" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-tsconfig": "workspace:^", | ||
"undici": "^5.23.0", | ||
"wrangler": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
async fetch() { | ||
return new Response("foo"); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { resolve } from "node:path"; | ||
import { assert, describe, it } from "vitest"; | ||
import { execSync } from "node:child_process"; | ||
|
||
describe("durable objects", () => { | ||
it("should throw an error when the worker doesn't export a durable object but requires one", ({ | ||
expect, | ||
}) => { | ||
let err: string = ""; | ||
try { | ||
execSync("pnpm run dev", { | ||
cwd: resolve(__dirname, ".."), | ||
}); | ||
assert(false); // Should never reach this | ||
} catch (e) { | ||
err = (e as Error).message | ||
.replaceAll("✘", "X") | ||
.replace(/\\/g, "/") | ||
.replace(/[^\S\n]+\n/g, "\n") | ||
.trimEnd(); | ||
} | ||
expect(err).toMatchInlineSnapshot(` | ||
"Command failed: pnpm run dev | ||
[31mX [41;31m[[41;97mERROR[41;31m][0m [1mYour Worker depends on the following Durable Objects, which are not exported in your entrypoint file: FooBar.[0m | ||
You should export these objects from your entrypoint, src/index.js." | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@cloudflare/workers-tsconfig/tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["node"] | ||
}, | ||
"include": ["**/*.ts", "../../../node-types.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"esModuleInterop": true, | ||
"module": "CommonJS", | ||
"lib": ["ES2020"], | ||
"types": ["node"], | ||
"moduleResolution": "node", | ||
"noEmit": true | ||
}, | ||
"include": ["tests", "../../node-types.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name = "do-worker-app" | ||
compatibility_date = "2022-03-31" | ||
|
||
main = "src/index.js" | ||
|
||
[durable_objects] | ||
bindings = [ | ||
{ name = "MY_DO", class_name = "FooBar" } | ||
] | ||
|
||
[[migrations]] | ||
tag = "v1" | ||
new_classes = ["FooBar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.