Skip to content

Commit 1b9c41e

Browse files
committed
changed: toml file/path parsing
1 parent 8e8ab2e commit 1b9c41e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/app/config.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@ pub fn read_config() -> Vec<Connection> {
1111
let home = std::env::var("HOME").unwrap();
1212

1313
// Full path to the toml config file.
14-
let toml_path = PathBuf::from(format!("{home}/.config/lantern/config.toml"));
14+
let toml_path = PathBuf::from(home)
15+
.join(".config")
16+
.join("lantern")
17+
.join("config.toml");
1518

16-
let mut f = std::fs::File::open(&toml_path).unwrap();
19+
let Ok(mut f) = std::fs::File::open(&toml_path) else {
20+
eprintln!(
21+
"ERROR: failed to read configuration file: {}",
22+
toml_path.display()
23+
);
24+
std::process::exit(1);
25+
};
1726

1827
let mut buf = String::new();
19-
f.read_to_string(&mut buf)
20-
.expect("Failed to read contents of TOML config file.");
28+
29+
if f.read_to_string(&mut buf).is_err() {
30+
eprintln!(
31+
"ERROR: failed to read configuration file: {}",
32+
toml_path.display()
33+
);
34+
std::process::exit(1);
35+
}
2136

2237
let c: ConfigFile = toml::from_str(&buf).unwrap();
2338

0 commit comments

Comments
 (0)