fix(cosmic_config): Make get_local return key_path() error
It looks like this was changed to be like this in cd8f4ee85. But
`key_path()` only seems to return `Error::NoConfigDirectory` or
`Error::InvalidName`, so it seems reasonable to just update `get()` to
also check for `NoConfigDirectory`. (`get_local()` doesn't seem
to be used elsewhere, so I don't see nay issues this can cause.)
This commit is contained in:
parent
8415d77b0a
commit
00f7580012
1 changed files with 9 additions and 10 deletions
|
|
@ -322,23 +322,22 @@ impl ConfigGet for Config {
|
||||||
fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T, Error> {
|
fn get<T: DeserializeOwned>(&self, key: &str) -> Result<T, Error> {
|
||||||
match self.get_local(key) {
|
match self.get_local(key) {
|
||||||
Ok(value) => Ok(value),
|
Ok(value) => Ok(value),
|
||||||
Err(Error::NotFound) => self.get_system_default(key),
|
Err(Error::NoConfigDirectory | Error::NotFound) => self.get_system_default(key),
|
||||||
Err(why) => Err(why),
|
Err(why) => Err(why),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_local<T: DeserializeOwned>(&self, key: &str) -> Result<T, Error> {
|
fn get_local<T: DeserializeOwned>(&self, key: &str) -> Result<T, Error> {
|
||||||
// If key path exists
|
// If key path exists
|
||||||
match self.key_path(key) {
|
let key_path = self.key_path(key)?;
|
||||||
Ok(key_path) if key_path.is_file() => {
|
if key_path.is_file() {
|
||||||
// Load user override
|
// Load user override
|
||||||
let data = fs::read_to_string(key_path)
|
let data =
|
||||||
.map_err(|err| Error::GetKey(key.to_string(), err))?;
|
fs::read_to_string(key_path).map_err(|err| Error::GetKey(key.to_string(), err))?;
|
||||||
|
|
||||||
Ok(ron::from_str(&data)?)
|
Ok(ron::from_str(&data)?)
|
||||||
}
|
} else {
|
||||||
|
Err(Error::NotFound)
|
||||||
_ => Err(Error::NotFound),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue