mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 14:16:43 +00:00
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.
This commit is contained in:
+15
-10
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user