From 1fa2b5eef1dcd017cd68f0e5e78c6934846e93dc Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Fri, 20 Sep 2024 13:52:53 +0200 Subject: [PATCH] refactor(dev): attach worker reload error as `cause` (#2651) Co-authored-by: Pooya Parsa --- src/core/dev-server/server.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/dev-server/server.ts b/src/core/dev-server/server.ts index 0ed046db79..7fd90cef37 100644 --- a/src/core/dev-server/server.ts +++ b/src/core/dev-server/server.ts @@ -45,10 +45,14 @@ function initWorker(filename: string): Promise | undefined { ) ); }); - worker.once("error", (err) => { - const newErr = new Error("[worker init] " + err.message); - newErr.stack = err.stack; - reject(newErr); + worker.once("error", (error) => { + const newError = new Error(`[worker init] ${filename} failed`, { + cause: error, + }); + if (Error.captureStackTrace) { + Error.captureStackTrace(newError, initWorker); + } + reject(newError); }); const addressListener = (event: any) => { if (!event || !event?.address) {