File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ pub mod runtime_error;
1717pub 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}
Original file line number Diff line number Diff line change 11use 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+ }
You can’t perform that action at this time.
0 commit comments