Load a JSONC file for **editing**. Unlike [`load_jsonc_file`], this returns an error if the file exists but cannot be parsed after comment stripping, preventing silent data loss when the modified value is written back. # Error conditions - File exists but is not readable (permissions, I/O error). - File exists and has content but contains invalid JSONC. Returns `Ok(json!({}))` only when the file
(path: &Path)
| 1136 | /// |
| 1137 | /// Returns `Ok(json!({}))` only when the file does not exist or is empty. |
| 1138 | pub fn load_jsonc_file_strict(path: &Path) -> Result<serde_json::Value> { |
| 1139 | if !path.exists() { |
| 1140 | return Ok(serde_json::json!({})); |
| 1141 | } |
| 1142 | let contents = std::fs::read_to_string(path).map_err(|e| TraceDecayError::Config { |
| 1143 | message: format!("cannot read {}: {e}", path.display()), |
| 1144 | })?; |
| 1145 | if contents.trim().is_empty() { |
| 1146 | return Ok(serde_json::json!({})); |
| 1147 | } |
| 1148 | let stripped = strip_jsonc_comments(&contents); |
| 1149 | serde_json::from_str(&stripped).map_err(|e| TraceDecayError::Config { |
| 1150 | message: format!( |
| 1151 | "cannot parse {} as JSONC: {e}\n \ |
| 1152 | Hint: fix the JSON syntax manually and re-run the command,\n \ |
| 1153 | or delete the file to start fresh", |
| 1154 | path.display() |
| 1155 | ), |
| 1156 | }) |
| 1157 | } |
| 1158 | |
| 1159 | /// Returns the VS Code user data directory, platform-specific. |
| 1160 | pub fn vscode_data_dir(home: &Path) -> PathBuf { |