use event.message when no event.error in HMR during event

This commit is contained in:
Alistair Smith
2025-12-05 11:14:45 -08:00
parent 4d60b6f69d
commit 438aaf9e95
2 changed files with 11 additions and 2 deletions

View File

@@ -615,7 +615,6 @@ const NativeStackFrame = ({
<div
title={StackFrameScope[scope]}
className="BunError-StackFrame-identifier"
// @ts-expect-error Custom CSS variables are not known by TypeScript
style={{ "--max-length": `${maxLength}ch` }}
>
{getNativeStackFrameIdentifier(frame)}

View File

@@ -237,8 +237,18 @@ function onHmrLoadError(event: Event | string, source?: string, lineno?: number,
}
window.addEventListener("error", event => {
onRuntimeError(event.error, true, false);
// In rare cases the error property might be null
// but it's unlikely that both error and message are gone
const value = event.error || event.message;
if (!value) {
console.log(
"[Bun] The HMR client detected a runtime error, but no useful value was found. Below is the full error event:",
);
console.log(event);
}
onRuntimeError(value, true, false);
});
window.addEventListener("unhandledrejection", event => {
onRuntimeError(event.reason, true, true);
});