fix(cli-tools): tolerate JSONC configs in CLI tool settings routes
readConfig/readSettings/readJson across all CLI tool settings routes used JSON.parse() but only caught ENOENT, re-throwing SyntaxError on any corrupted or JSONC-formatted config file. The API would return 500, which the UI misinterpreted as "tool not installed." This patch: - strips trailing commas before parsing (handles JSONC from opencode, etc.) - returns null on any parse error instead of re-throwing, so the UI shows "installed but not configured" (accurate) instead of "not installed" - applies the same fix to all 8 affected routes: opencode, openclaw, kilo, droid, cowork, copilot, claude, and cline Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
committed by
decolua
co-authored by
Cursor
parent
f6c2f7cae3
commit
6c10edf8ba
@@ -21,10 +21,12 @@ const getConfigPath = () => {
|
||||
const readConfig = async () => {
|
||||
try {
|
||||
const content = await fs.readFile(getConfigPath(), "utf-8");
|
||||
return JSON.parse(content);
|
||||
// Tolerate JSONC (trailing commas) and treat unparseable files as "no config"
|
||||
// rather than throwing a 500 that the UI misreads as "tool not installed".
|
||||
const stripped = content.replace(/,(\s*[}\]])/g, "$1");
|
||||
return JSON.parse(stripped);
|
||||
} catch (error) {
|
||||
if (error.code === "ENOENT") return null;
|
||||
throw error;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user