(error: unknown)
| 82 | } |
| 83 | |
| 84 | export function toErrorMessage(error: unknown): string { |
| 85 | const appError = extractAppCommandError(error) |
| 86 | if (appError) { |
| 87 | return appError.detail?.trim() || appError.message |
| 88 | } |
| 89 | |
| 90 | if (error instanceof Error) { |
| 91 | return error.message.trim() |
| 92 | } |
| 93 | |
| 94 | if (typeof error === "string") { |
| 95 | return error.trim() |
| 96 | } |
| 97 | |
| 98 | try { |
| 99 | const serialized = JSON.stringify(error) |
| 100 | return serialized ? serialized.trim() : String(error) |
| 101 | } catch { |
| 102 | return String(error) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /** Translator callable shape compatible with next-intl's scoped translator. */ |
| 107 | export type AppErrorTranslator = ( |
no test coverage detected