fix(cli): Improve error messages on config.json loading, closes #1227

This commit is contained in:
Andrew Hlynskyi 2021-07-03 04:07:47 +03:00
parent ad30779d90
commit 13108baef7

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