0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-04-07 23:41:43 -05:00

Prevent render ansi in error overlay (#9547)

This commit is contained in:
Bjorn Lu 2023-12-30 18:06:40 +07:00 committed by GitHub
parent 8049f0cd91
commit 22f42d11a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Prevents ANSI codes from rendering in the error overlay

View file

@ -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