From cd319710a741185d0a5f03f2a26a352b7254cc00 Mon Sep 17 00:00:00 2001 From: Dario Piotrowicz Date: Wed, 22 Jan 2025 12:01:00 +0000 Subject: [PATCH] [vite-plugin-cloudflare] make sure that runner initialization is properly validated (#7846) --- .changeset/smart-mice-appear.md | 5 +++++ .../vite-plugin-cloudflare/src/cloudflare-environment.ts | 5 ++++- .../vite-plugin-cloudflare/src/runner-worker/index.ts | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 .changeset/smart-mice-appear.md diff --git a/.changeset/smart-mice-appear.md b/.changeset/smart-mice-appear.md new file mode 100644 index 000000000000..f25dd156e171 --- /dev/null +++ b/.changeset/smart-mice-appear.md @@ -0,0 +1,5 @@ +--- +"@cloudflare/vite-plugin": patch +--- + +fix: make sure that runner initialization is properly validated diff --git a/packages/vite-plugin-cloudflare/src/cloudflare-environment.ts b/packages/vite-plugin-cloudflare/src/cloudflare-environment.ts index 8abf3a7bb52e..0fafd734abb8 100644 --- a/packages/vite-plugin-cloudflare/src/cloudflare-environment.ts +++ b/packages/vite-plugin-cloudflare/src/cloudflare-environment.ts @@ -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"); diff --git a/packages/vite-plugin-cloudflare/src/runner-worker/index.ts b/packages/vite-plugin-cloudflare/src/runner-worker/index.ts index 8ae08fe0fd82..ef88e20c1299 100644 --- a/packages/vite-plugin-cloudflare/src/runner-worker/index.ts +++ b/packages/vite-plugin-cloudflare/src/runner-worker/index.ts @@ -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 }); }