bug 1526938: geckodriver: convert ExitCode to consts; r=whimboo
authorAndreas Tolfsen <ato@sny.no>
Mon, 18 Feb 2019 12:48:32 +0000
changeset 520648 f11ef576312915f2eefdaaf1cfaceb29ff27e9f8
parent 520647 e2a10e5049be9a0b63cc6b6bec92ae9b6d517edc
child 520649 342fcc83b61361b143724490c49bda27bc4a4f0d
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswhimboo
bugs1526938
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1526938: geckodriver: convert ExitCode to consts; r=whimboo We don't need an enum for exit codes as we never have to match on them. Converting them to consts also has the benefit that we will not have to coerce them to i32. i32 is the correct type to use here, since it is what std::process::exit() takes and what the libc crate uses. Depends on D19424 Differential Revision: https://phabricator.services.mozilla.com/D19425
testing/geckodriver/src/main.rs
--- a/testing/geckodriver/src/main.rs
+++ b/testing/geckodriver/src/main.rs
@@ -44,23 +44,21 @@ mod marionette;
 mod prefs;
 
 #[cfg(test)]
 pub mod test;
 
 use crate::command::extension_routes;
 use crate::marionette::{MarionetteHandler, MarionetteSettings};
 
-type ProgramResult = std::result::Result<(), (ExitCode, String)>;
+const EXIT_SUCCESS: i32 = 0;
+const EXIT_USAGE: i32 = 64;
+const EXIT_UNAVAILABLE: i32 = 69;
 
-enum ExitCode {
-    Ok = 0,
-    Usage = 64,
-    Unavailable = 69,
-}
+type ProgramResult = std::result::Result<(), (i32, String)>;
 
 fn app<'a, 'b>() -> App<'a, 'b> {
     App::new(format!("geckodriver {}", build::BuildInfo))
         .about("WebDriver implementation for Firefox")
         .arg(
             Arg::with_name("webdriver_host")
                 .long("host")
                 .value_name("HOST")
@@ -147,30 +145,30 @@ fn run() -> ProgramResult {
     let host = matches.value_of("webdriver_host").unwrap();
     let port = match u16::from_str(
         matches
             .value_of("webdriver_port")
             .or(matches.value_of("webdriver_port_alias"))
             .unwrap(),
     ) {
         Ok(x) => x,
-        Err(_) => return Err((ExitCode::Usage, "invalid WebDriver port".into())),
+        Err(_) => return Err((EXIT_USAGE, "invalid WebDriver port".into())),
     };
     let addr = match IpAddr::from_str(host) {
         Ok(addr) => SocketAddr::new(addr, port),
-        Err(_) => return Err((ExitCode::Usage, "invalid host address".into())),
+        Err(_) => return Err((EXIT_USAGE, "invalid host address".into())),
     };
 
     let binary = matches.value_of("binary").map(PathBuf::from);
 
     let marionette_host = matches.value_of("marionette_host").unwrap().to_string();
     let marionette_port = match matches.value_of("marionette_port") {
         Some(x) => match u16::from_str(x) {
             Ok(x) => Some(x),
-            Err(_) => return Err((ExitCode::Usage, "invalid Marionette port".into())),
+            Err(_) => return Err((EXIT_USAGE, "invalid Marionette port".into())),
         },
         None => None,
     };
 
     let log_level = if matches.is_present("log_level") {
         logging::Level::from_str(matches.value_of("log_level").unwrap()).ok()
     } else {
         match matches.occurrences_of("verbosity") {
@@ -189,33 +187,33 @@ fn run() -> ProgramResult {
         host: marionette_host,
         port: marionette_port,
         binary,
         connect_existing: matches.is_present("connect_existing"),
         jsdebugger: matches.is_present("jsdebugger"),
     };
     let handler = MarionetteHandler::new(settings);
     let listening = webdriver::server::start(addr, handler, &extension_routes()[..])
-        .map_err(|err| (ExitCode::Unavailable, err.to_string()))?;
+        .map_err(|err| (EXIT_UNAVAILABLE, err.to_string()))?;
     debug!("Listening on {}", listening.socket);
 
     Ok(())
 }
 
 fn main() {
     let exit_code = match run() {
-        Ok(_) => ExitCode::Ok,
+        Ok(_) => EXIT_SUCCESS,
         Err((exit_code, reason)) => {
             error!("{}", reason);
             exit_code
         }
     };
 
     std::io::stdout().flush().unwrap();
-    std::process::exit(exit_code as i32);
+    std::process::exit(exit_code);
 }
 
 fn print_version() {
     println!("geckodriver {}", build::BuildInfo);
     println!("");
     println!("The source code of this program is available from");
     println!("testing/geckodriver in https://hg.mozilla.org/mozilla-central.");
     println!("");