File tree 1 file changed +13
-8
lines changed
1 file changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -214,21 +214,26 @@ impl<F: ErrorFormatter> Error<F> {
214
214
}
215
215
}
216
216
217
+ /// Returns the exit code that `.exit` will exit the process with.
218
+ ///
219
+ /// When the error's kind would print to `stderr` this returns `2`,
220
+ /// else it returns `0`.
221
+ pub fn exit_code ( & self ) -> i32 {
222
+ if self . use_stderr ( ) {
223
+ USAGE_CODE
224
+ } else {
225
+ SUCCESS_CODE
226
+ }
227
+ }
228
+
217
229
/// Prints the error and exits.
218
230
///
219
231
/// Depending on the error kind, this either prints to `stderr` and exits with a status of `2`
220
232
/// or prints to `stdout` and exits with a status of `0`.
221
233
pub fn exit ( & self ) -> ! {
222
- if self . use_stderr ( ) {
223
- // Swallow broken pipe errors
224
- let _ = self . print ( ) ;
225
-
226
- safe_exit ( USAGE_CODE ) ;
227
- }
228
-
229
234
// Swallow broken pipe errors
230
235
let _ = self . print ( ) ;
231
- safe_exit ( SUCCESS_CODE )
236
+ safe_exit ( self . exit_code ( ) )
232
237
}
233
238
234
239
/// Prints formatted and colored error to `stdout` or `stderr` according to its error kind
You can’t perform that action at this time.
0 commit comments