Preserve all error stack lines (#4364)

This commit is contained in:
Bjorn Lu 2022-08-18 14:36:31 +08:00 committed by GitHub
parent 41b81d0d7e
commit 77b068086d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Preserve all error stack lines

View file

@ -37,7 +37,6 @@ export interface ErrorWithMetadata {
export function cleanErrorStack(stack: string) {
return stack
.split(/\n/g)
.filter((l) => /^\s*at/.test(l))
.map((l) => l.replace(/\/@fs\//g, '/'))
.join('\n');
}

View file

@ -18,7 +18,7 @@ import type { AddressInfo } from 'net';
import os from 'os';
import { ZodError } from 'zod';
import type { AstroConfig } from '../@types/astro';
import { cleanErrorStack, ErrorWithMetadata } from './errors.js';
import { ErrorWithMetadata } from './errors.js';
import { emoji, getLocalAddress, padMultilineString } from './util.js';
const PREFIX_PADDING = 6;
@ -235,10 +235,10 @@ export function formatErrorMessage(err: ErrorWithMetadata, args: string[] = []):
args.push(red(padMultilineString(err.frame, 4)));
}
if (args.length === 1 && err.stack) {
args.push(dim(cleanErrorStack(err.stack)));
args.push(dim(err.stack));
} else if (err.stack) {
args.push(` ${bold('Stacktrace:')}`);
args.push(dim(cleanErrorStack(err.stack)));
args.push(dim(err.stack));
args.push(``);
}
return args.join('\n');