From 9793f19ecd4e64cbf3140454fe52aeee2c22c8c9 Mon Sep 17 00:00:00 2001 From: Mayank <9084735+mayank99@users.noreply.github.com> Date: Tue, 31 Jan 2023 04:12:42 -0500 Subject: [PATCH] error overlay: show `cause` if available (#6052) * show `cause` in error overlay * add extra check for string * add changeset --- .changeset/clever-panthers-end.md | 5 ++++ packages/astro/src/core/errors/dev/vite.ts | 2 ++ packages/astro/src/core/errors/overlay.ts | 29 +++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .changeset/clever-panthers-end.md diff --git a/.changeset/clever-panthers-end.md b/.changeset/clever-panthers-end.md new file mode 100644 index 000000000000..ac52a0bfb7f0 --- /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 57aad4e8ae20..4cc430ff66fc 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);