From ebce750d54753f717939aa30f4870b2f8c4e9c6f Mon Sep 17 00:00:00 2001 From: adevwithpurpose Date: Mon, 17 Aug 2026 10:36:40 -0300 Subject: [PATCH] fix(cli): normalize instrumentation boot errors Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --- src/instrumentation.ts | 5 +++-- .../instrumentation-hook-boot-fatal-log-10171.test.ts | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/instrumentation.ts b/src/instrumentation.ts index 87348b2741..f0e6d41ce6 100644 --- a/src/instrumentation.ts +++ b/src/instrumentation.ts @@ -34,9 +34,10 @@ export async function register(registerNodejsFn?: () => Promise) { // up while every DB-touching route 500s forever with a permanently // empty app.log. This guarantees stdout/app.log is never silently // empty on a failed boot, regardless of platform or which step threw. - const message = err instanceof Error ? err.message : String(err); + const normalizedError = err instanceof Error ? err : new Error(String(err)); + const message = normalizedError.message; console.error("[STARTUP] Fatal: instrumentation hook failed during boot:", message); - throw err; + throw normalizedError; } } } diff --git a/tests/unit/instrumentation-hook-boot-fatal-log-10171.test.ts b/tests/unit/instrumentation-hook-boot-fatal-log-10171.test.ts index 9242043d0d..6d0f790e3d 100644 --- a/tests/unit/instrumentation-hook-boot-fatal-log-10171.test.ts +++ b/tests/unit/instrumentation-hook-boot-fatal-log-10171.test.ts @@ -78,7 +78,15 @@ test("#10171: a non-Error throw during instrumentation-hook boot is still logged }; try { - await assert.rejects(() => register(fakeRegisterNodejs)); + await assert.rejects( + () => register(fakeRegisterNodejs), + (err: unknown) => { + assert.ok(err instanceof Error, "register() must rethrow a real Error instance"); + err.message += " (augmented by Next)"; + assert.equal(err.message, "raw string boot failure (augmented by Next)"); + return true; + } + ); const fatalLine = captured.find( (line) => line.includes("[STARTUP] Fatal:") && line.includes("raw string boot failure")