Skip to content

Commit

Permalink
conf: Only print a warning for unreadable config file
Browse files Browse the repository at this point in the history
Failure to parse is still a hard error, so far.
  • Loading branch information
vincentdephily committed Feb 7, 2024
1 parent 6a55387 commit 4880142
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/config/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@ impl Toml {
}
fn doload(name: &str) -> Result<Self, Error> {
log::debug!("Loading config {name:?}");
let mut f = File::open(name).with_context(|| format!("Cannot open {name:?}"))?;
let mut buf = String::new();
// TODO Streaming read
f.read_to_string(&mut buf).with_context(|| format!("Cannot read {name:?}"))?;
toml::from_str(&buf).with_context(|| format!("Cannot parse {name:?}"))
match File::open(name) {
Err(e) => {
log::warn!("Cannot open {name:?}: {e}");
Ok(Self::default())
},
Ok(mut f) => {
let mut buf = String::new();
f.read_to_string(&mut buf).with_context(|| format!("Cannot read {name:?}"))?;
toml::from_str(&buf).with_context(|| format!("Cannot parse {name:?}"))
},
}
}
}

0 comments on commit 4880142

Please sign in to comment.