From 78198e262b8c392866723aaca661598ac9d19680 Mon Sep 17 00:00:00 2001 From: wwminger Date: Wed, 15 Apr 2026 11:11:48 +0800 Subject: [PATCH] fix(opencode): use json5 parser for trailing comma tolerance (#2023) * fix(opencode): use json5 parser for trailing comma tolerance OpenCode CLI writes opencode.json with trailing commas (valid JSONC), but CC Switch parsed it with serde_json (strict JSON), causing errors like 'trailing comma at line 35 column 3'. Switch to json5::from_str which accepts both JSON and JSONC. The json5 crate is already a project dependency. Change error type from AppError::json() to AppError::Config() since json5::Error differs from serde_json::Error. * style(opencode): apply rustfmt to satisfy cargo fmt --check The previous commit's .map_err(...) chain exceeded rustfmt's default 100-char max_width, breaking CI's `cargo fmt --check`. Let rustfmt wrap the closure body as a multi-line block. No behavior change. --------- Co-authored-by: 18067889926 Co-authored-by: Jason --- src-tauri/src/opencode_config.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/opencode_config.rs b/src-tauri/src/opencode_config.rs index beb43b607..4e659e874 100644 --- a/src-tauri/src/opencode_config.rs +++ b/src-tauri/src/opencode_config.rs @@ -61,7 +61,12 @@ pub fn read_opencode_config() -> Result { } let content = std::fs::read_to_string(&path).map_err(|e| AppError::io(&path, e))?; - serde_json::from_str(&content).map_err(|e| AppError::json(&path, e)) + json5::from_str(&content).map_err(|e| { + AppError::Config(format!( + "Failed to parse OpenCode config: {}: {e}", + path.display() + )) + }) } pub fn write_opencode_config(config: &Value) -> Result<(), AppError> {