Skip to content

Commit f49b5c4

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

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

bin/miden-cli/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,17 @@ const CLIENT_CONFIG_FILE_NAME: &str = "miden-client.toml";
4343
/// name, then we simply display the standard "miden-client".
4444
pub fn client_binary_name() -> OsString {
4545
std::env::current_exe()
46-
.map(|executable| {
47-
executable
48-
.file_name()
49-
.expect("ERROR: failed to obtain the executable's file name")
50-
.to_os_string()
51-
})
5246
.inspect_err(|e| {
5347
eprintln!(
54-
"WARNING: Couldn't obtain the name of the current executable because of {e}.\
48+
"WARNING: Couldn't obtain the path of the current executable because of {e}.\
5549
Defaulting to miden-client."
5650
);
5751
})
52+
.and_then(|executable_path| {
53+
executable_path.file_name().map(std::ffi::OsStr::to_os_string).ok_or(
54+
std::io::Error::other("Couldn't obtain the file name of the current executable"),
55+
)
56+
})
5857
.unwrap_or(OsString::from("miden-client"))
5958
}
6059

0 commit comments

Comments
 (0)