Merge pull request #1234 from ahlinc/fix/imrove-config-loading-err-msgs

fix(cli): Improve error messages on config.json loading, closes #1227
This commit is contained in:
Max Brunsfeld 2021-07-15 20:37:40 -07:00 committed by GitHub
commit 64e6c11566
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 })
}