Skip to content

Commit

Permalink
fix: pass errorless ErrorEvent to dev overlay (#1647)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Carniato <[email protected]>
  • Loading branch information
katywings and ryansolid authored Oct 10, 2024
1 parent a5c279f commit 00a4908
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/long-pumpkins-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Show proper dev overlay for ErrorEvent with no error property.
26 changes: 18 additions & 8 deletions packages/start/src/shared/dev-overlay/DevOverlayDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ interface ErrorInfoProps {
}

function ErrorInfo(props: ErrorInfoProps): JSX.Element {
const error = createMemo(() => {
const e = props.error;

if (e instanceof Error) {
return { name: e.name, message: e.message };
}

if (e instanceof ErrorEvent) {
return { message: e.message };
}

return { message: (e as Error).toString() };
});

return (
<Show when={props.error instanceof Error && props.error} keyed fallback={<span>{(props.error as Error).toString()}</span>}>
{(current) => (
<span class="dev-overlay-error-info">
<span class="dev-overlay-error-info-name">{current.name}</span>
<span class="dev-overlay-error-info-message">{current.message}</span>
</span>
)}
</Show>
<span class="dev-overlay-error-info">
<span class="dev-overlay-error-info-name">{error().name}</span>
<span class="dev-overlay-error-info-message">{error().message}</span>
</span>
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/start/src/shared/dev-overlay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function DevOverlay(props: DevOverlayProps): JSX.Element {

createEffect(() => {
const onErrorEvent = (error: ErrorEvent) => {
pushError(error.error);
pushError(error.error ?? error);
};

window.addEventListener("error", onErrorEvent);
Expand Down

0 comments on commit 00a4908

Please sign in to comment.