fix(config): improve YAML error messages and thinking validation

- U3: show line/column/snippet for YAML syntax errors

- W2: warn when thinking: true used instead of object
This commit is contained in:
kaitranntt
2026-01-08 16:55:31 -05:00
parent d5652de634
commit f7cc9f4653
+27 -2
View File
@@ -108,8 +108,23 @@ export function loadUnifiedConfig(): UnifiedConfig | null {
return parsed;
} catch (err) {
const error = err instanceof Error ? err.message : 'Unknown error';
console.error(`[X] Failed to load config: ${error}`);
// U3: Provide better context for YAML syntax errors
if (err instanceof yaml.YAMLException) {
const mark = err.mark;
console.error(`[X] YAML syntax error in ${yamlPath}:`);
console.error(
` Line ${(mark?.line ?? 0) + 1}, Column ${(mark?.column ?? 0) + 1}: ${err.reason || 'Invalid syntax'}`
);
if (mark?.snippet) {
console.error(` ${mark.snippet}`);
}
console.error(
` Tip: Check for missing colons, incorrect indentation, or unquoted special characters.`
);
} else {
const error = err instanceof Error ? err.message : 'Unknown error';
console.error(`[X] Failed to load config: ${error}`);
}
return null;
}
}
@@ -598,6 +613,16 @@ export function getGlobalEnvConfig(): GlobalEnvConfig {
*/
export function getThinkingConfig(): ThinkingConfig {
const config = loadOrCreateUnifiedConfig();
// W2: Check for invalid thinking config (e.g., thinking: true instead of object)
if (config.thinking !== undefined && typeof config.thinking !== 'object') {
console.warn(
`[!] Invalid thinking config: expected object, got ${typeof config.thinking}. Using defaults.`
);
console.warn(` Tip: Use 'thinking: { mode: auto }' instead of 'thinking: true'`);
return DEFAULT_THINKING_CONFIG;
}
return {
mode: config.thinking?.mode ?? DEFAULT_THINKING_CONFIG.mode,
override: config.thinking?.override,