(ev: Omit<FailureEvent, 'ts'>)
| 118 | } |
| 119 | |
| 120 | export async function recordFailure(ev: Omit<FailureEvent, 'ts'>): Promise<void> { |
| 121 | try { |
| 122 | const full = failuresPath(); |
| 123 | await fs.mkdir(path.dirname(full), { recursive: true }); |
| 124 | await fs.appendFile(full, JSON.stringify({ ts: new Date().toISOString(), ...ev }) + '\n', 'utf-8'); |
| 125 | } catch (e: any) { |
| 126 | logger.debug('Failure not recorded', { err: e?.message }); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /** Read the failure log (most recent `limit` events, to bound memory). */ |
| 131 | export async function readFailures(limit = 2000): Promise<FailureEvent[]> { |
no test coverage detected