render error cause in render-inline-error.ts

This commit is contained in:
Hazelnoot 2025-05-22 11:15:26 -04:00
parent 4540614f7b
commit c8797451e3

View file

@ -7,6 +7,21 @@ import { IdentifiableError } from '@/misc/identifiable-error.js';
import { StatusError } from '@/misc/status-error.js';
export function renderInlineError(err: unknown): string {
if (err instanceof Error) {
const text = printError(err);
if (err.cause) {
const cause = renderInlineError(err.cause);
return `${text} [caused by]: ${cause}`;
} else {
return text;
}
}
return String(err);
}
function printError(err: Error): string {
if (err instanceof IdentifiableError) {
if (err.message) {
return `${err.name} ${err.id}: ${err.message}`;
@ -25,13 +40,9 @@ export function renderInlineError(err: unknown): string {
}
}
if (err instanceof Error) {
if (err.message) {
return `${err.name}: ${err.message}`;
} else {
return err.name;
}
}
return String(err);
}