Skip to content

Commit 10075fd

Browse files
bukinoshitacursoragentfelipefreitag
authored
fix: clean up telemetry temp files on flush failure (#194)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com> Co-authored-by: Felipe Freitag Vargas <ffvargas@gmail.com>
1 parent 83b10b4 commit 10075fd

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/lib/telemetry.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ export async function flushFromFile(filePath: string): Promise<void> {
192192
closeSync(fd);
193193
}
194194

195-
await flushPayload(payload);
196-
unlinkSync(resolved);
195+
try {
196+
await flushPayload(payload);
197+
} finally {
198+
unlinkSync(resolved);
199+
}
197200
}

tests/lib/telemetry.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,12 @@ describe('flushFromFile', () => {
449449
}
450450
});
451451

452-
it('preserves file when flush fails', async () => {
452+
it('deletes file even when flush fails', async () => {
453453
fetchSpy.mockResolvedValue({ ok: false, status: 500 } as Response);
454454
const payload = JSON.stringify({ event: 'test' });
455455
writeFileSync(tmpFile, payload);
456456

457457
await expect(flushFromFile(tmpFile)).rejects.toThrow();
458-
expect(existsSync(tmpFile)).toBe(true);
458+
expect(existsSync(tmpFile)).toBe(false);
459459
});
460460
});

0 commit comments

Comments
 (0)