Skip to content

Commit 4fa5251

Browse files
committed
fix(12-04): add try-catch to JSON.parse in RoadmapPlanningService
- Wrap JSON.parse in try-catch block - Provide descriptive error message on parse failure - Improves error handling for malformed AI responses
1 parent c78f750 commit 4fa5251

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/services/RoadmapPlanningService.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,15 @@ Return ONLY valid JSON. Start sprints from today's date (${new Date().toISOStrin
172172
// Parse JSON response
173173
const jsonMatch = response.text.match(/\{[\s\S]*\}/);
174174
if (!jsonMatch) {
175-
throw new Error('Failed to parse AI response for roadmap');
175+
throw new Error('Failed to extract JSON from AI response for roadmap');
176176
}
177177

178-
return JSON.parse(jsonMatch[0]);
178+
try {
179+
return JSON.parse(jsonMatch[0]);
180+
} catch (parseError) {
181+
const message = parseError instanceof Error ? parseError.message : String(parseError);
182+
throw new Error(`Failed to parse roadmap JSON: ${message}`);
183+
}
179184
}
180185

181186
/**

0 commit comments

Comments
 (0)