Skip to content

Commit 9e0c870

Browse files
refactor: remove expect and leave only a single unwrap
Signed-off-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com> Suggested-by: Francisco Krause Arnim <francisco.krause@lambdaclass.com>
1 parent 3f03515 commit 9e0c870

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

bin/miden-cli/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@ const CLIENT_CONFIG_FILE_NAME: &str = "miden-client.toml";
4545
/// name, then we simply display the standard "miden-client".
4646
pub fn client_binary_name() -> OsString {
4747
std::env::current_exe()
48-
.map(|executable| {
49-
executable
50-
.file_name()
51-
.expect("ERROR: failed to obtain the executable's file name")
52-
.to_os_string()
53-
})
5448
.inspect_err(|e| {
5549
eprintln!(
56-
"WARNING: Couldn't obtain the name of the current executable because of {e}.\
50+
"WARNING: Couldn't obtain the path of the current executable because of {e}.\
5751
Defaulting to miden-client."
5852
);
5953
})
54+
.and_then(|executable_path| {
55+
executable_path.file_name().and_then(|name| Some(name.to_os_string())).ok_or(
56+
std::io::Error::new(
57+
std::io::ErrorKind::Other,
58+
"Couldn't obtain the file name of the current executable",
59+
),
60+
)
61+
})
6062
.unwrap_or(OsString::from("miden-client"))
6163
}
6264

0 commit comments

Comments
 (0)