mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-08 08:29:42 +02:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -25,19 +25,19 @@ async function readLinkedCases(): Promise<Record<string, string>> {
|
|||||||
try {
|
try {
|
||||||
return JSON.parse(await fs.readFile(LINKED_CASES_FILE, 'utf-8'));
|
return JSON.parse(await fs.readFile(LINKED_CASES_FILE, 'utf-8'));
|
||||||
} catch (err) {
|
} 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);
|
console.warn('[Server] Failed to read linked cases:', err);
|
||||||
}
|
}
|
||||||
return {};
|
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<string> {
|
async function resolveCasePath(name: string): Promise<string> {
|
||||||
const casePath = join(CASES_DIR, name);
|
|
||||||
if (existsSync(casePath)) return casePath;
|
|
||||||
const linkedCases = await readLinkedCases();
|
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 {
|
export function registerCaseRoutes(app: FastifyInstance, ctx: EventPort & ConfigPort): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user