logancyang_obsidian-copilot/src/errorFormat.ts
Zero Liu 500bc347a0
chore(eslint): enable no-unsafe-member-access; fix 124 violations (#2438)
Enables @typescript-eslint/no-unsafe-member-access globally. Tests and 41
heavy source files (>5 violations each) are exempted via per-file overrides
with current violation counts annotated for follow-up PRs. Fixes 124
violations across 51 source files using narrow type assertions, instanceof
Error guards, and proper structural types instead of blanket any casts.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 22:35:38 -07:00

17 lines
608 B
TypeScript

export function err2String(err: unknown, stack = false): string {
try {
if (err instanceof Error) {
const cause = (err as { cause?: unknown }).cause;
const causeMsg = cause instanceof Error ? cause.message : cause ? String(cause as any) : "";
const stackStr = stack && err.stack ? err.stack : "";
const parts = [err.message];
if (causeMsg) parts.push(`more message: ${causeMsg}`);
if (stackStr) parts.push(stackStr);
return parts.join("\n");
}
const json = JSON.stringify(err);
return json ?? String(err);
} catch {
return String(err);
}
}