// Extract a human-readable message from an unknown thrown value. // // `String(err)` on a non-Error object yields the useless "[object Object]", // which is exactly what surfaced when native modules (whisper.rn, the audio // decoder, file system) reject with a plain `{ message, code }`-shaped object // instead of an `Error`. This pulls the most useful text out of whatever was // thrown so the UI shows something actionable. export function errorMessage(err: unknown): string { if (err instanceof Error) return err.message; if (typeof err === 'string') return err; if (err && typeof err === 'object') { const o = err as { message?: unknown; reason?: unknown; code?: unknown }; const parts = [o.message, o.reason, o.code] .filter((x) => x != null && x !== '') .map(String); if (parts.length > 0) return parts.join(' — '); try { return JSON.stringify(err); } catch { /* fall through to String() for circular/unserializable objects */ } } return String(err); }