(path: &Path)
| 247 | } |
| 248 | |
| 249 | fn read_json_object(path: &Path) -> AgentResult<Map<String, Value>> { |
| 250 | if !path.exists() { |
| 251 | return Ok(Map::new()); |
| 252 | } |
| 253 | let content = std::fs::read_to_string(path).map_err(|e| AgentError::ConfigError { |
| 254 | operation: "read".to_string(), |
| 255 | path: path.to_path_buf(), |
| 256 | reason: e.to_string(), |
| 257 | })?; |
| 258 | if content.trim().is_empty() { |
| 259 | return Ok(Map::new()); |
| 260 | } |
| 261 | let value: Value = serde_json::from_str(&content).map_err(|e| AgentError::ConfigError { |
| 262 | operation: "parse".to_string(), |
| 263 | path: path.to_path_buf(), |
| 264 | reason: e.to_string(), |
| 265 | })?; |
| 266 | match value { |
| 267 | Value::Object(map) => Ok(map), |
| 268 | _ => Ok(Map::new()), |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | fn write_json_object(path: &Path, root: &Map<String, Value>) -> AgentResult<()> { |
| 273 | if let Some(parent) = path.parent() { |
no test coverage detected