(
err: unknown,
context: { diagnosticId?: string; logPath?: string } = {},
)
| 78 | } |
| 79 | |
| 80 | export function normalizeError( |
| 81 | err: unknown, |
| 82 | context: { diagnosticId?: string; logPath?: string } = {}, |
| 83 | ): NormalizedError { |
| 84 | const appErr = asAppError(err); |
| 85 | const details = appErr.details ? redactDiagnosticData(appErr.details) : undefined; |
| 86 | const detailHint = details && typeof details.hint === 'string' ? details.hint : undefined; |
| 87 | const diagnosticId = |
| 88 | (details && typeof details.diagnosticId === 'string' ? details.diagnosticId : undefined) ?? |
| 89 | context.diagnosticId; |
| 90 | const logPath = |
| 91 | (details && typeof details.logPath === 'string' ? details.logPath : undefined) ?? |
| 92 | context.logPath; |
| 93 | const hint = detailHint ?? defaultHintForCode(appErr.code); |
| 94 | const cleanDetails = stripDiagnosticMeta(details); |
| 95 | const message = maybeEnrichCommandFailedMessage(appErr.code, appErr.message, details); |
| 96 | |
| 97 | return { |
| 98 | code: appErr.code, |
| 99 | message, |
| 100 | hint, |
| 101 | diagnosticId, |
| 102 | logPath, |
| 103 | details: cleanDetails, |
| 104 | }; |
| 105 | } |
| 106 | |
| 107 | function maybeEnrichCommandFailedMessage( |
| 108 | code: string, |
no test coverage detected