Commit 9d19c68
Eric Wheeler
fix: wrap JSON.parse calls in try/catch blocks
Add error handling for JSON parsing failures in readApiMessages:
- Wrap JSON.parse calls in try/catch blocks for both current and legacy history files
- Add detailed error logging with taskId and file paths
- Return empty arrays when parsing fails to maintain function contract
- Improve existing debug logging for empty history arrays
- Handle file unlinking even when parsing fails
This prevents crashes from malformed JSON in history files and provides
better debugging information when API conversation history is corrupted.
Related to issue #4311.
Signed-off-by: Eric Wheeler <[email protected]>1 parent 49a68c1 commit 9d19c68
1 file changed
+24
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
27 | 34 | | |
28 | | - | |
| 35 | + | |
29 | 36 | | |
| 37 | + | |
30 | 38 | | |
31 | | - | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
36 | 43 | | |
37 | | - | |
38 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
39 | 54 | | |
40 | | - | |
| 55 | + | |
41 | 56 | | |
| 57 | + | |
| 58 | + | |
42 | 59 | | |
43 | | - | |
44 | | - | |
45 | 60 | | |
46 | 61 | | |
47 | 62 | | |
| |||
0 commit comments