From 0ad4e0ea2470772a2065e5e50c2c455161b901cd Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 15 Mar 2026 03:50:45 +0100 Subject: [PATCH] fix: correct resolveCasePath priority order and suppress JSON parse warnings - resolveCasePath now checks linked cases first (matching original behavior of /api/cases/:name and /api/cases/:name/fix-plan handlers) - readLinkedCases only warns on real I/O errors, not JSON parse errors (SyntaxError has no .code property, so check for .code existence first) Co-Authored-By: Claude Opus 4.6 --- src/web/routes/case-routes.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/web/routes/case-routes.ts b/src/web/routes/case-routes.ts index 745ef861..89e9232b 100644 --- a/src/web/routes/case-routes.ts +++ b/src/web/routes/case-routes.ts @@ -25,19 +25,19 @@ async function readLinkedCases(): Promise> { try { return JSON.parse(await fs.readFile(LINKED_CASES_FILE, 'utf-8')); } catch (err) { - if ((err as NodeJS.ErrnoException).code !== 'ENOENT') { + // Only warn on real I/O errors, not ENOENT (file missing) or SyntaxError (corrupted JSON) + if ((err as NodeJS.ErrnoException).code && (err as NodeJS.ErrnoException).code !== 'ENOENT') { console.warn('[Server] Failed to read linked cases:', err); } return {}; } } -/** Resolve a case name to its directory path, checking linked cases if not in CASES_DIR. */ +/** Resolve a case name to its directory path, checking linked cases first, then CASES_DIR. */ async function resolveCasePath(name: string): Promise { - const casePath = join(CASES_DIR, name); - if (existsSync(casePath)) return casePath; const linkedCases = await readLinkedCases(); - return linkedCases[name] ?? casePath; + if (linkedCases[name]) return linkedCases[name]; + return join(CASES_DIR, name); } export function registerCaseRoutes(app: FastifyInstance, ctx: EventPort & ConfigPort): void {