From 4405a97d9b69490ac411acc082f5e432f5f8996f Mon Sep 17 00:00:00 2001 From: Cody Seibert Date: Sun, 14 Dec 2025 18:18:21 -0500 Subject: [PATCH] fix: enhance error logging for JSON parsing in suggestions generation - Added error logging for failed JSON parsing in the suggestions generation route to improve debugging capabilities. - This change ensures that any parsing errors are captured and logged, aiding in the identification of issues with AI response handling. --- apps/server/src/routes/app-spec/routes/status.ts | 5 +---- apps/server/src/routes/setup/routes/api-keys.ts | 9 +++------ .../src/routes/suggestions/generate-suggestions.ts | 2 ++ apps/server/src/routes/suggestions/routes/status.ts | 6 +----- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/apps/server/src/routes/app-spec/routes/status.ts b/apps/server/src/routes/app-spec/routes/status.ts index 1ecc6ab2..a3c1aac1 100644 --- a/apps/server/src/routes/app-spec/routes/status.ts +++ b/apps/server/src/routes/app-spec/routes/status.ts @@ -3,10 +3,7 @@ */ import type { Request, Response } from "express"; -import { - getSpecRegenerationStatus, - getErrorMessage, -} from "../common.js"; +import { getSpecRegenerationStatus, getErrorMessage } from "../common.js"; export function createStatusHandler() { return async (_req: Request, res: Response): Promise => { diff --git a/apps/server/src/routes/setup/routes/api-keys.ts b/apps/server/src/routes/setup/routes/api-keys.ts index b2b09d27..e292503a 100644 --- a/apps/server/src/routes/setup/routes/api-keys.ts +++ b/apps/server/src/routes/setup/routes/api-keys.ts @@ -3,18 +3,15 @@ */ import type { Request, Response } from "express"; -import { - getApiKey, - getErrorMessage, - logError, -} from "../common.js"; +import { getApiKey, getErrorMessage, logError } from "../common.js"; export function createApiKeysHandler() { return async (_req: Request, res: Response): Promise => { try { res.json({ success: true, - hasAnthropicKey: !!getApiKey("anthropic") || !!process.env.ANTHROPIC_API_KEY, + hasAnthropicKey: + !!getApiKey("anthropic") || !!process.env.ANTHROPIC_API_KEY, hasGoogleKey: !!getApiKey("google") || !!process.env.GOOGLE_API_KEY, }); } catch (error) { diff --git a/apps/server/src/routes/suggestions/generate-suggestions.ts b/apps/server/src/routes/suggestions/generate-suggestions.ts index 11c7b9b1..14c02abe 100644 --- a/apps/server/src/routes/suggestions/generate-suggestions.ts +++ b/apps/server/src/routes/suggestions/generate-suggestions.ts @@ -106,6 +106,8 @@ Format your response as JSON: throw new Error("No valid JSON found in response"); } } catch (error) { + // Log the parsing error for debugging + logger.error("Failed to parse suggestions JSON from AI response:", error); // Return generic suggestions if parsing fails events.emit("suggestions:event", { type: "suggestions_complete", diff --git a/apps/server/src/routes/suggestions/routes/status.ts b/apps/server/src/routes/suggestions/routes/status.ts index b7492d87..d62dfa17 100644 --- a/apps/server/src/routes/suggestions/routes/status.ts +++ b/apps/server/src/routes/suggestions/routes/status.ts @@ -3,11 +3,7 @@ */ import type { Request, Response } from "express"; -import { - getSuggestionsStatus, - getErrorMessage, - logError, -} from "../common.js"; +import { getSuggestionsStatus, getErrorMessage, logError } from "../common.js"; export function createStatusHandler() { return async (_req: Request, res: Response): Promise => {