diff rust/rhg/src/main.rs @ 45361:47997afadf08

rhg: ask the error message from `CommandError` Avoid repeating the display of the same error messages in different commands. Differential Revision: https://phab.mercurial-scm.org/D8865
author Antoine Cezar <antoine.cezar@octobus.net>
date Mon, 20 Jul 2020 18:14:52 +0200
parents 18f8d3b31baa
children 26440adbe3e9
line wrap: on
line diff
--- a/rust/rhg/src/main.rs	Tue Jul 21 10:39:30 2020 +0200
+++ b/rust/rhg/src/main.rs	Mon Jul 20 18:14:52 2020 +0200
@@ -22,9 +22,11 @@
         std::process::exit(exitcode::UNIMPLEMENTED_COMMAND)
     });
 
+    let ui = ui::Ui::new();
+
     let command_result = match matches.subcommand_name() {
         Some(name) => match name {
-            "root" => commands::root::RootCommand::new().run(),
+            "root" => commands::root::RootCommand::new(&ui).run(),
             _ => std::process::exit(exitcode::UNIMPLEMENTED_COMMAND),
         },
         _ => {
@@ -37,6 +39,15 @@
 
     match command_result {
         Ok(_) => std::process::exit(exitcode::OK),
-        Err(e) => e.exit(),
+        Err(e) => {
+            let message = e.get_error_message_bytes();
+            if let Some(msg) = message {
+                match ui.write_stderr(&msg) {
+                    Ok(_) => (),
+                    Err(_) => std::process::exit(exitcode::ABORT),
+                };
+            };
+            e.exit()
+        }
     }
 }