mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 12:19:35 +00:00
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:
@@ -108,8 +108,23 @@ export function loadUnifiedConfig(): UnifiedConfig | null {
|
|||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const error = err instanceof Error ? err.message : 'Unknown error';
|
// U3: Provide better context for YAML syntax errors
|
||||||
console.error(`[X] Failed to load config: ${error}`);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -598,6 +613,16 @@ export function getGlobalEnvConfig(): GlobalEnvConfig {
|
|||||||
*/
|
*/
|
||||||
export function getThinkingConfig(): ThinkingConfig {
|
export function getThinkingConfig(): ThinkingConfig {
|
||||||
const config = loadOrCreateUnifiedConfig();
|
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 {
|
return {
|
||||||
mode: config.thinking?.mode ?? DEFAULT_THINKING_CONFIG.mode,
|
mode: config.thinking?.mode ?? DEFAULT_THINKING_CONFIG.mode,
|
||||||
override: config.thinking?.override,
|
override: config.thinking?.override,
|
||||||
|
|||||||
Reference in New Issue
Block a user