fix(cli): Improve error messages on config.json loading, closes
//! Manages tree-sitter's configuration file.
-use anyhow::{anyhow, Result};
+use anyhow::{anyhow, Context, Result};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::path::PathBuf;
@@ -64,8 +64,10 @@ impl Config {
Some(location) => location,
None => return Config::initial(),
};
- let content = fs::read_to_string(&location)?;
- let config = serde_json::from_str(&content)?;
+ let content = fs::read_to_string(&location)
+ .with_context(|| format!("Failed to read {}", &location.to_string_lossy()))?;
+ let config = serde_json::from_str(&content)
+ .with_context(|| format!("Bad JSON config {}", &location.to_string_lossy()))?;
Ok(Config { location, config })
}
