Skip to content

Commit

Permalink
clarify what the error handler does
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 16, 2021
1 parent d2d35af commit 4f87a78
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ fn main() {
match open::that(&path_or_url) {
Ok(status) if status.success() => (),
Ok(status) => match status.code() {
Some(code) => open_error(code, &path_or_url, &format!("error code: {}", code)),
None => open_error(3, &path_or_url, "error unknown"),
Some(code) => print_error_and_exit(code, &path_or_url, &format!("error code: {}", code)),
None => print_error_and_exit(3, &path_or_url, "error unknown"),
},
Err(err) => open_error(3, &path_or_url, &err.to_string()),
Err(err) => print_error_and_exit(3, &path_or_url, &err.to_string()),
}
}

fn open_error(code: i32, path: &str, error_message: &str) {
fn print_error_and_exit(code: i32, path: &str, error_message: &str) -> ! {
eprintln!(
"An error occurred when opening '{}': {}",
path, error_message
Expand Down

0 comments on commit 4f87a78

Please sign in to comment.