Skip to content

Commit 2c5fcda

Browse files
committed
.csmrc: If present but unreadable, don't continue
This indicates that the user likely intended to use a .csmrc config, but for some reason it could not be read (e.g. due to permissions). Bail out early in this case.
1 parent a20ad98 commit 2c5fcda

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/csmrc.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ impl Config {
2424
return Ok(Self::default());
2525
};
2626
let csmrc_path = home.join(".csmrc");
27-
let Ok(csmrc_data) = std::fs::read_to_string(csmrc_path) else {
28-
debug!("No .csmrc found, using defaults");
29-
return Ok(Config::default());
30-
};
31-
let config =
32-
serde_yaml_ng::from_str(&csmrc_data).map_err(|e| Error::new(ErrorKind::InvalidData, e));
33-
debug!("config: {:?}", config);
34-
config
27+
match std::fs::read_to_string(csmrc_path) {
28+
Err(e) if e.kind() == ErrorKind::NotFound => {
29+
debug!("No .csmrc found, using defaults");
30+
return Ok(Config::default());
31+
},
32+
Err(e) => return Err(e),
33+
Ok(csmrc_data) => {
34+
let config =
35+
serde_yaml_ng::from_str(&csmrc_data).map_err(|e| Error::new(ErrorKind::InvalidData, e));
36+
debug!("config: {:?}", config);
37+
config
38+
}
39+
}
3540
}
3641
}

0 commit comments

Comments
 (0)