summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/config.rs b/src/config.rs
index 3708639..8e303d4 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -152,10 +152,19 @@ impl Default for Config {
}
impl Config {
- pub fn load(root: &Path) -> anyhow::Result<Self> {
+ /// Read `<root>/config.json`.
+ ///
+ /// The crate's own error type, like everything else that can fail (m-15):
+ /// `anyhow::Result` here meant two error vocabularies in one crate, and the
+ /// one thing a caller can actually branch on — "there is no config yet, run
+ /// init" — arrived as an opaque string.
+ pub fn load(root: &Path) -> crate::error::Result<Self> {
let p = root.join("config.json");
if !p.exists() {
- anyhow::bail!("no config at {}; run `aur-build init`", p.display());
+ return Err(crate::error::Error::not_found(format!(
+ "no config at {}; run `aur-build init`",
+ p.display()
+ )));
}
let s = std::fs::read_to_string(&p)?;
let mut cfg: Config = serde_json::from_str(&s)?;
@@ -167,7 +176,7 @@ impl Config {
Ok(cfg)
}
- pub fn save(&self) -> anyhow::Result<()> {
+ pub fn save(&self) -> crate::error::Result<()> {
std::fs::create_dir_all(&self.root)?;
std::fs::write(
self.root.join("config.json"),
@@ -209,7 +218,7 @@ impl Config {
}
/// Create the directory tree the server needs. Idempotent.
- pub fn ensure_dirs(&self) -> anyhow::Result<()> {
+ pub fn ensure_dirs(&self) -> crate::error::Result<()> {
for d in [
self.root.clone(),
self.mirrors_dir(),