From ebfbaeba544ab09fded741589bb30c19ff0355ac Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Sun, 23 Feb 2025 09:28:03 +0100 Subject: [PATCH] fix(core): capture stack for HMR errors (#60067) Currently we send the `message` of an error thrown during HMR. That's usually not enough so now we also capture the stack trace. Relates to https://github.com/angular/angular-cli/issues/29695. PR Close #60067 --- packages/core/src/render3/hmr.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/core/src/render3/hmr.ts b/packages/core/src/render3/hmr.ts index cc20246696f..527f46415d0 100644 --- a/packages/core/src/render3/hmr.ts +++ b/packages/core/src/render3/hmr.ts @@ -308,12 +308,13 @@ function executeWithInvalidateFallback( try { callback(); } catch (e) { - const errorMessage = (e as {message?: string}).message; + const error = e as {message?: string; stack?: string}; // If we have all the necessary information and APIs to send off the invalidation // request, send it before rethrowing so the dev server can decide what to do. - if (id !== null && errorMessage) { - importMeta?.hot?.send?.('angular:invalidate', {id, message: errorMessage, error: true}); + if (id !== null && error.message) { + const toLog = error.message + (error.stack ? '\n' + error.stack : ''); + importMeta?.hot?.send?.('angular:invalidate', {id, message: toLog, error: true}); } // Throw the error in case the page doesn't get refreshed.