Skip to content

Commit

Permalink
Prevent render ansi in error overlay (#9547)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Dec 30, 2023
1 parent 8049f0c commit 22f42d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-weeks-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Prevents ANSI codes from rendering in the error overlay
10 changes: 8 additions & 2 deletions packages/astro/src/core/errors/dev/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 22f42d1

Please sign in to comment.