// Human-readable messages for errors surfaced in the UI. // // @atproto/oauth-client wraps failures in its own error types (an // OAuthResolverError around a fetch or DID-resolution failure, say), and the // outer message is usually the generic one — "Failed to resolve identity" // rather than what actually went wrong. Walking the `cause` chain is what makes // a sign-in failure diagnosable from the screen instead of the debugger. export function errorMessage(e: unknown): string { const parts: string[] = []; let cur: unknown = e; // Guard against a cyclic cause chain, which would otherwise loop forever. const seen = new Set(); while (cur && !seen.has(cur)) { seen.add(cur); parts.push(cur instanceof Error ? cur.message : String(cur)); cur = cur instanceof Error ? (cur as { cause?: unknown }).cause : undefined; } return parts.join(" ‹cause› "); }