export function errorMessage(error: unknown): string { if (error instanceof Error) return error.message; if (error && typeof error === 'object') { if ('message' in error && typeof error.message === 'string') return error.message; try { const text = String(error); if (text !== '[object Object]') return text; } catch { // Ignore objects without a string coercion (such as Object.create(null)). } try { const json = JSON.stringify(error); if (typeof json === 'string') return json; } catch { // Fall back for unserializable values (such as circular references). } return 'Unknown error'; } try { return String(error); } catch { return 'Unknown error'; } }