From 4f87a7888049b182ede9e00a057c2cc625152ef9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 16 Jul 2021 15:09:55 +0800 Subject: [PATCH] clarify what the error handler does --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3eec851..63ab93e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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