fix(cli): normalize instrumentation boot errors

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
This commit is contained in:
adevwithpurpose
2026-08-17 10:36:40 -03:00
parent 3e0ef5b4bb
commit ebce750d54
2 changed files with 12 additions and 3 deletions

View File

@@ -34,9 +34,10 @@ export async function register(registerNodejsFn?: () => Promise<void>) {
// 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;
}
}
}

View File

@@ -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")