From a4a473ac93a3adf9b51a0e9371bbd48fa7363157 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Fri, 26 Dec 2025 13:47:17 -0500 Subject: [PATCH] fix(config): use safe inline logic in getSettingsPath() legacy fallback The try/catch around loadConfig() in getSettingsPath() was ineffective because process.exit() cannot be caught by try/catch - it terminates the process immediately. Replace with inline safe logic that: 1. Checks if config.json exists with fs.existsSync() 2. Reads and parses JSON manually 3. Uses isConfig() type guard for validation 4. Properly catches JSON parse errors This ensures unified mode users don't crash when falling back to check legacy config.json for profiles not found in config.yaml. --- src/utils/config-manager.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/utils/config-manager.ts b/src/utils/config-manager.ts index 02b4e6db..a28938e5 100644 --- a/src/utils/config-manager.ts +++ b/src/utils/config-manager.ts @@ -163,19 +163,24 @@ export function getSettingsPath(profile: string): string { // If not found in unified config, try legacy config.json as fallback if (!settingsPath) { - try { - const legacyConfig = loadConfig(); - if (legacyConfig.profiles[profile]) { - settingsPath = legacyConfig.profiles[profile]; - // Merge legacy profiles into available list (avoid duplicates) - for (const p of Object.keys(legacyConfig.profiles)) { - if (!availableProfiles.includes(p)) { - availableProfiles.push(p); + // Use inline safe logic - loadConfig() calls process.exit() which cannot be caught + const configPath = getConfigPath(); + if (fs.existsSync(configPath)) { + try { + const raw = fs.readFileSync(configPath, 'utf8'); + const legacyConfig: unknown = JSON.parse(raw); + if (isConfig(legacyConfig) && legacyConfig.profiles[profile]) { + settingsPath = legacyConfig.profiles[profile]; + // Merge legacy profiles into available list (avoid duplicates) + for (const p of Object.keys(legacyConfig.profiles)) { + if (!availableProfiles.includes(p)) { + availableProfiles.push(p); + } } } + } catch { + // Legacy config is invalid JSON - that's OK in unified mode } - } catch { - // Legacy config doesn't exist or is invalid - that's OK in unified mode } } } else {