(e: unknown, maxFrames = 5)
| 159 | * waste context tokens. Keep the full stack in debug logs instead. |
| 160 | */ |
| 161 | export function shortErrorStack(e: unknown, maxFrames = 5): string { |
| 162 | if (!(e instanceof Error)) return String(e) |
| 163 | if (!e.stack) return e.message |
| 164 | // V8/Bun stack format: "Name: message\n at frame1\n at frame2..." |
| 165 | // First line is the message; subsequent " at " lines are frames. |
| 166 | const lines = e.stack.split('\n') |
| 167 | const header = lines[0] ?? e.message |
| 168 | const frames = lines.slice(1).filter(l => l.trim().startsWith('at ')) |
| 169 | if (frames.length <= maxFrames) return e.stack |
| 170 | return [header, ...frames.slice(0, maxFrames)].join('\n') |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * True if the error means the path is missing, inaccessible, or |
no outgoing calls
no test coverage detected