(error: unknown)
| 26 | } |
| 27 | |
| 28 | function formatCommandErrorDetails(error: unknown): string[] { |
| 29 | const details: string[] = []; |
| 30 | if (!error || typeof error !== 'object') { |
| 31 | details.push('Unknown error occurred'); |
| 32 | return details; |
| 33 | } |
| 34 | |
| 35 | const commandError = error as CommandError; |
| 36 | |
| 37 | for (const [label, stream] of [ |
| 38 | ['stderr', commandError.stderr], |
| 39 | ['stdout', commandError.stdout], |
| 40 | ] as const) { |
| 41 | const cleaned = cleanCommandOutput(streamToText(stream)); |
| 42 | if (cleaned) { |
| 43 | details.push(`${label}:\n${cleaned}`); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (details.length === 0) { |
| 48 | const reason = commandError.killed |
| 49 | ? 'Process was killed (likely timed out)' |
| 50 | : commandError.code === 'ETIMEDOUT' |
| 51 | ? 'Process timed out' |
| 52 | : commandError.code === 'ENOENT' |
| 53 | ? 'Command not found — check that the required CLI is installed and on PATH' |
| 54 | : 'No error output captured'; |
| 55 | details.push(reason); |
| 56 | } |
| 57 | |
| 58 | return details; |
| 59 | } |
| 60 | |
| 61 | function printCommandErrorDetails(error: unknown, indent = ' '): void { |
| 62 | for (const detail of formatCommandErrorDetails(error)) { |
no test coverage detected