diff --git a/cli/config/src/lib.rs b/cli/config/src/lib.rs index 289de595..a09694e4 100644 --- a/cli/config/src/lib.rs +++ b/cli/config/src/lib.rs @@ -1,6 +1,6 @@ //! 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; @@ -65,8 +65,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 }) }