mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-07-07 12:36:57 +00:00
render error cause in render-inline-error.ts
This commit is contained in:
parent
4540614f7b
commit
c8797451e3
1 changed files with 19 additions and 8 deletions
|
@ -7,6 +7,21 @@ import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||||
import { StatusError } from '@/misc/status-error.js';
|
import { StatusError } from '@/misc/status-error.js';
|
||||||
|
|
||||||
export function renderInlineError(err: unknown): string {
|
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 instanceof IdentifiableError) {
|
||||||
if (err.message) {
|
if (err.message) {
|
||||||
return `${err.name} ${err.id}: ${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) {
|
||||||
if (err.message) {
|
return `${err.name}: ${err.message}`;
|
||||||
return `${err.name}: ${err.message}`;
|
} else {
|
||||||
} else {
|
return err.name;
|
||||||
return err.name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return String(err);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue