diff --git a/.changeset/clever-panthers-end.md b/.changeset/clever-panthers-end.md new file mode 100644 index 0000000000..ac52a0bfb7 --- /dev/null +++ b/.changeset/clever-panthers-end.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Error overlay will now show the error's `cause` if available. diff --git a/packages/astro/src/core/errors/dev/vite.ts b/packages/astro/src/core/errors/dev/vite.ts index 57aad4e8ae..4cc430ff66 100644 --- a/packages/astro/src/core/errors/dev/vite.ts +++ b/packages/astro/src/core/errors/dev/vite.ts @@ -118,6 +118,7 @@ export interface AstroErrorPayload { line?: number; column?: number; }; + cause?: unknown; }; } @@ -174,6 +175,7 @@ export async function getViteErrorPayload(err: ErrorWithMetadata): PromiseStack Trace
+ +
+

Cause

+
+
`; @@ -593,6 +605,17 @@ class ErrorOverlay extends HTMLElement { this.text('#title', err.title); this.text('#message-content', err.message, true); + const cause = this.root.querySelector('#cause'); + if (cause && err.cause) { + if (typeof err.cause === 'string') { + this.text('#cause-content', err.cause); + cause.style.display = 'block'; + } else { + this.text('#cause-content', JSON.stringify(err.cause, null, 2)); + cause.style.display = 'block'; + } + } + const hint = this.root.querySelector('#hint'); if (hint && err.hint) { this.text('#hint-content', err.hint, true);