mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-05-20 20:33:22 +08:00
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 <ming.flute@outlook.com> Co-authored-by: Jason <farion1231@gmail.com>
This commit is contained in:
@@ -61,7 +61,12 @@ pub fn read_opencode_config() -> Result<Value, AppError> {
|
||||
}
|
||||
|
||||
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> {
|
||||
|
||||
Reference in New Issue
Block a user