Use more accurate error variants in Repo::config()
Unexpected git failures now surface as Error::Git rather than
Error::NotFound, and UTF-8 decoding failures use Error::Io with
InvalidData rather than Error::NotFound.
Assisted-by: GLM-5.1 via pi
diff --git a/src/error.rs b/src/error.rs
index 7ec6b81..7f4940c 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -14,6 +14,9 @@ pub enum Error {
#[error("fennel error: {0}")]
Fennel(String),
+
+ #[error("git error: {0}")]
+ Git(String),
}
pub type Result<T> = std::result::Result<T, Error>;
diff --git a/src/quire.rs b/src/quire.rs
index 0828b55..fd552d2 100644
--- a/src/quire.rs
+++ b/src/quire.rs
@@ -71,13 +71,17 @@ impl Repo {
return Ok(RepoConfig::default());
}
// Unexpected git error.
- return Err(crate::Error::NotFound(format!(
+ return Err(crate::Error::Git(format!(
"failed to read HEAD:.quire/config.fnl: {stderr}"
)));
}
- let source = String::from_utf8(output.stdout)
- .map_err(|e| crate::Error::NotFound(format!("config is not valid UTF-8: {e}")))?;
+ let source = String::from_utf8(output.stdout).map_err(|e| {
+ crate::Error::Io(std::io::Error::new(
+ std::io::ErrorKind::InvalidData,
+ format!("config is not valid UTF-8: {e}"),
+ ))
+ })?;
let fennel = Fennel::new().map_err(|e| crate::Error::Fennel(e.to_string()))?;
fennel