diff options
-rw-r--r-- | .changeset/quiet-weeks-teach.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/errors/dev/utils.ts | 10 |
2 files changed, 13 insertions, 2 deletions
diff --git a/.changeset/quiet-weeks-teach.md b/.changeset/quiet-weeks-teach.md new file mode 100644 index 000000000..bfbbb737c --- /dev/null +++ b/.changeset/quiet-weeks-teach.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Prevents ANSI codes from rendering in the error overlay diff --git a/packages/astro/src/core/errors/dev/utils.ts b/packages/astro/src/core/errors/dev/utils.ts index fd69b74db..7db29c2f8 100644 --- a/packages/astro/src/core/errors/dev/utils.ts +++ b/packages/astro/src/core/errors/dev/utils.ts @@ -26,7 +26,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): Erro err.forEach((error) => { if (e.stack) { const stackInfo = collectInfoFromStacktrace(e); - error.stack = stackInfo.stack; + error.stack = stripAnsi(stackInfo.stack); error.loc = stackInfo.loc; error.plugin = stackInfo.plugin; error.pluginCode = stackInfo.pluginCode; @@ -57,7 +57,7 @@ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): Erro if (!error.frame) { const frame = codeFrame(fileContents, error.loc); - error.frame = frame; + error.frame = stripAnsi(frame); } if (!error.fullCode) { @@ -68,6 +68,12 @@ export function collectErrorMetadata(e: any, rootFolder?: URL | undefined): Erro // Generic error (probably from Vite, and already formatted) error.hint = generateHint(e); + + // Strip ANSI for `message` property. Note that ESBuild errors may not have the property, + // but it will be handled and added below, which is already ANSI-free + if (error.message) { + error.message = stripAnsi(error.message); + } }); // If we received an array of errors and it's not from us, it's most likely from ESBuild, try to extract info for Vite to display |