Skip to content

Commit db8d0ea

Browse files
committed
config: Don't fail if file doesn't exist
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent f7f7117 commit db8d0ea

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

framework_lib/src/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ struct Platform {
1717
const CONFIG_FILE: &str = "framework_tool_config.toml";
1818

1919
#[cfg(feature = "uefi")]
20-
fn read_config_file() -> String {
21-
crate::uefi::fs::shell_read_file(CONFIG_FILE)
20+
fn read_config_file() -> Option<String> {
21+
Some(crate::uefi::fs::shell_read_file(CONFIG_FILE))
2222
}
2323
#[cfg(not(feature = "uefi"))]
24-
fn read_config_file() -> String {
25-
let mut path = std::env::current_exe().unwrap();
24+
fn read_config_file() -> Option<String> {
25+
let mut path = std::env::current_exe().ok()?;
2626
path.pop();
2727
path.push(CONFIG_FILE);
2828

2929
if let Ok(str) = std::fs::read_to_string(path) {
30-
str
30+
Some(str)
3131
} else {
3232
path = CONFIG_FILE.into();
33-
std::fs::read_to_string(path).unwrap()
33+
Some(std::fs::read_to_string(path).ok()?)
3434
}
3535
}
3636

3737
pub fn load_config() -> Option<util::Platform> {
38-
let toml_str = read_config_file();
38+
let toml_str = read_config_file()?;
3939

4040
let decoded: Config = toml::from_str(&toml_str).unwrap();
4141
println!("{:?}", decoded);

0 commit comments

Comments
 (0)