Skip to content

Commit 9d4eaa3

Browse files
committed
feat: different exit codes for different errors
Resolves #292
1 parent 89af88c commit 9d4eaa3

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub mod runtime_error;
1717
pub fn main() -> std::process::ExitCode {
1818
if let Err(error) = app::App::from_env().run() {
1919
eprintln!("[error] {error}");
20-
return std::process::ExitCode::FAILURE;
20+
return error.code();
2121
}
2222
std::process::ExitCode::SUCCESS
2323
}

src/runtime_error.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use derive_more::{Display, Error};
2-
use std::convert::Infallible;
2+
use std::{convert::Infallible, process::ExitCode};
33

44
/// Error caused by the CLI program.
55
#[derive(Debug, Display, Error)]
@@ -39,3 +39,16 @@ impl From<Infallible> for RuntimeError {
3939
match value {}
4040
}
4141
}
42+
43+
impl RuntimeError {
44+
/// Convert error into exit code.
45+
pub fn code(&self) -> ExitCode {
46+
ExitCode::from(match self {
47+
RuntimeError::SerializationFailure(_) => 2,
48+
RuntimeError::DeserializationFailure(_) => 3,
49+
RuntimeError::JsonInputArgConflict => 4,
50+
RuntimeError::InvalidInputReflection(_) => 5,
51+
RuntimeError::UnsupportedFeature(_) => 6,
52+
})
53+
}
54+
}

0 commit comments

Comments
 (0)