Skip to content

Commit

Permalink
[vite-plugin-cloudflare] make sure that runner initialization is prop…
Browse files Browse the repository at this point in the history
…erly validated (#7846)
  • Loading branch information
dario-piotrowicz authored Jan 22, 2025
1 parent 51ce630 commit cd31971
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-mice-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/vite-plugin": patch
---

fix: make sure that runner initialization is properly validated
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export class CloudflareDevEnvironment extends vite.DevEnvironment {
}
);

assert(response.ok, "Failed to initialize module runner");
assert(
response.ok,
`Failed to initialize module runner, error: ${await response.text()}`
);

const webSocket = response.webSocket;
assert(webSocket, "Failed to establish WebSocket");
Expand Down
9 changes: 8 additions & 1 deletion packages/vite-plugin-cloudflare/src/runner-worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,14 @@ export function createWorkerEntrypointWrapper(

if (url.pathname === INIT_PATH) {
const { 0: client, 1: server } = new WebSocketPair();
createModuleRunner(this.env, server);
try {
await createModuleRunner(this.env, server);
} catch (e) {
return new Response(
e instanceof Error ? e.message : JSON.stringify(e),
{ status: 500 }
);
}

return new Response(null, { status: 101, webSocket: client });
}
Expand Down

0 comments on commit cd31971

Please sign in to comment.