diff options
| author | Teddy Wing | 2021-03-14 03:42:16 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2021-03-14 03:43:44 +0100 | 
| commit | 0fa5b304ed57517ba04b7a42ff30258e456972f8 (patch) | |
| tree | 60d9adde4763ba8652cc02b15468e06a94d2b954 /src | |
| parent | dca32c260c0ecd85e01a7bbef07192bc4c8a2290 (diff) | |
| download | mutt-ottolangy-0fa5b304ed57517ba04b7a42ff30258e456972f8.tar.bz2 | |
Exit with sysexits.h error codes on error
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 16 | 
1 files changed, 15 insertions, 1 deletions
| diff --git a/src/main.rs b/src/main.rs index 2775155..a50b42d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@  // along with this program. If not, see <https://www.gnu.org/licenses/>.  use anyhow::{anyhow, Context, Error}; +use exitcode;  use mailparse;  use thiserror;  use whatlang::{self, Lang}; @@ -21,6 +22,7 @@ use xdg;  use std::fs::File;  use std::io::{self, Read, Write}; +use std::process;  const PROGRAM_NAME: &'static str = "ottolangy"; @@ -59,7 +61,19 @@ enum OttolangyError {  fn main() {      match run() {          Ok(_) => (), -        Err(e) => eprintln!("{}: error: {}", PROGRAM_NAME, e), +        Err(e) => { +            eprintln!("{}: error: {}", PROGRAM_NAME, e); + +            match e.downcast_ref::<OttolangyError>() { +                Some(OttolangyError::ParseMail(_)) => +                    process::exit(exitcode::DATAERR), +                Some(OttolangyError::ParseMailUnknown) => +                    process::exit(exitcode::DATAERR), +                Some(OttolangyError::Xdg(_)) => process::exit(exitcode::IOERR), +                Some(OttolangyError::Io(_)) => process::exit(exitcode::IOERR), +                None => process::exit(exitcode::UNAVAILABLE), +            } +        },      }  } | 
