Skip to content

Commit 2890759

Browse files
committed
Prevent panic when config directory is unavailable
In some environments (such as within containers), the XDG_CONFIG directory is not available. In this case, reading the config should behave as if the file was not present instead of panicking.
1 parent cf4b97f commit 2890759

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/client/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,16 @@ impl ClientConfiguration {
3636
}
3737

3838
pub async fn from_default_file() -> Result<Self, ConfigFileError> {
39-
let default_file = dirs::config_dir()
40-
.expect("Config dir should be known")
41-
.join("numtracker")
42-
.join("config");
43-
match Self::from_file(default_file).await {
44-
Err(ConfigFileError::MissingFile) => Ok(Self::default()),
39+
let Some(file) = dirs::config_dir().map(|cnf| cnf.join("numtracker").join("config")) else {
40+
debug!("Unable to determine default file location - using default config");
41+
return Ok(Self::default());
42+
};
43+
44+
match Self::from_file(&file).await {
45+
Err(ConfigFileError::MissingFile) => {
46+
debug!("Config file {file:?} not present - using default config");
47+
Ok(Self::default())
48+
}
4549
res => res,
4650
}
4751
}

0 commit comments

Comments
 (0)