[1/3] Rework main() to return a Result()
diff mbox series

Message ID 20181213024353.19725-1-mpe@ellerman.id.au
State Accepted
Headers show
Series
  • [1/3] Rework main() to return a Result()
Related show

Commit Message

Michael Ellerman Dec. 13, 2018, 2:43 a.m. UTC
Turn main() into run() and have it return a Result(). Then in main()
we print a message for the error case.

We could just return Result() directly from main() but that prints the
Err() with {:?} which is ugly.
---
 src/main.rs | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

Comments

Andrew Donnellan Dec. 13, 2018, 3:07 a.m. UTC | #1
On 13/12/18 1:43 pm, Michael Ellerman wrote:
> Turn main() into run() and have it return a Result(). Then in main()
> we print a message for the error case.
> 
> We could just return Result() directly from main() but that prints the
> Err() with {:?} which is ugly.

add a signoff

otherwise,

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

> ---
>   src/main.rs | 19 +++++++++++++++----
>   1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/src/main.rs b/src/main.rs
> index 7a0debaebec4..2e022a3939e9 100644
> --- a/src/main.rs
> +++ b/src/main.rs
> @@ -45,8 +45,10 @@ use env_logger::Builder;
>   use log::LevelFilter;
>   
>   use std::env;
> +use std::error::Error;
>   use std::fs;
>   use std::path::Path;
> +use std::process;
>   use std::string::String;
>   use std::sync::Arc;
>   use std::thread;
> @@ -282,7 +284,7 @@ fn test_patch(
>   }
>   
>   #[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
> -fn main() {
> +fn run() -> Result<(), Box<Error>> {
>       let mut log_builder = Builder::new();
>       // By default, log at the "info" level for every module
>       log_builder.filter(None, LevelFilter::Info);
> @@ -358,7 +360,7 @@ fn main() {
>                   test_patch(&settings, &client, &project, &mbox, true);
>               }
>           }
> -        return;
> +        return Ok(());
>       }
>   
>       if args.flag_series > 0 {
> @@ -385,7 +387,7 @@ fn main() {
>                   }
>               }
>           }
> -        return;
> +        return Ok(());
>       }
>   
>       // At this point, specifying a project is required
> @@ -396,7 +398,7 @@ fn main() {
>           let patch = Path::new(&args.flag_mbox);
>           test_patch(&settings, &client, &project, patch, true);
>   
> -        return;
> +        return Ok(());
>       }
>   
>       /*
> @@ -491,4 +493,13 @@ fn main() {
>           info!("Finished testing new revisions, sleeping.");
>           thread::sleep(Duration::new(settings.patchwork.polling_interval * 60, 0));
>       }
> +
> +    Ok(())
> +}
> +
> +fn main() {
> +     if let Err(e) = run() {
> +        println!("Error: {}", e);
> +        process::exit(1);
> +    }
>   }
>
Andrew Donnellan Dec. 13, 2018, 3:17 a.m. UTC | #2
On 13/12/18 1:43 pm, Michael Ellerman wrote:
> Turn main() into run() and have it return a Result(). Then in main()
> we print a message for the error case.
> 
> We could just return Result() directly from main() but that prints the
> Err() with {:?} which is ugly.

Series applied to master: 7a52b417bf71ee91937ee95cde82c8a268c33087

(With Signed-off-bys added)


Thanks,
Michael Ellerman Dec. 14, 2018, 6:07 a.m. UTC | #3
Andrew Donnellan <andrew.donnellan@au1.ibm.com> writes:

> On 13/12/18 1:43 pm, Michael Ellerman wrote:
>> Turn main() into run() and have it return a Result(). Then in main()
>> we print a message for the error case.
>> 
>> We could just return Result() directly from main() but that prints the
>> Err() with {:?} which is ugly.
>
> Series applied to master: 7a52b417bf71ee91937ee95cde82c8a268c33087
>
> (With Signed-off-bys added)

Thanks!

cheers

Patch
diff mbox series

diff --git a/src/main.rs b/src/main.rs
index 7a0debaebec4..2e022a3939e9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -45,8 +45,10 @@  use env_logger::Builder;
 use log::LevelFilter;
 
 use std::env;
+use std::error::Error;
 use std::fs;
 use std::path::Path;
+use std::process;
 use std::string::String;
 use std::sync::Arc;
 use std::thread;
@@ -282,7 +284,7 @@  fn test_patch(
 }
 
 #[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))]
-fn main() {
+fn run() -> Result<(), Box<Error>> {
     let mut log_builder = Builder::new();
     // By default, log at the "info" level for every module
     log_builder.filter(None, LevelFilter::Info);
@@ -358,7 +360,7 @@  fn main() {
                 test_patch(&settings, &client, &project, &mbox, true);
             }
         }
-        return;
+        return Ok(());
     }
 
     if args.flag_series > 0 {
@@ -385,7 +387,7 @@  fn main() {
                 }
             }
         }
-        return;
+        return Ok(());
     }
 
     // At this point, specifying a project is required
@@ -396,7 +398,7 @@  fn main() {
         let patch = Path::new(&args.flag_mbox);
         test_patch(&settings, &client, &project, patch, true);
 
-        return;
+        return Ok(());
     }
 
     /*
@@ -491,4 +493,13 @@  fn main() {
         info!("Finished testing new revisions, sleeping.");
         thread::sleep(Duration::new(settings.patchwork.polling_interval * 60, 0));
     }
+
+    Ok(())
+}
+
+fn main() {
+     if let Err(e) = run() {
+        println!("Error: {}", e);
+        process::exit(1);
+    }
 }