File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,28 @@ def tar(source, destination):
182
182
shell .call (args + [source ], stderr = shell .DEVNULL )
183
183
184
184
185
+ def process_system_exit (e : SystemExit ) -> int :
186
+ # According to Python's documents, `SystemExit.code` is the exit status
187
+ # or error message that is passed to the constructor. (Defaults to None.)
188
+ #
189
+ # This means that `SystemExit.code` is either `None`, an `int` object or
190
+ # a `string` object of error message.
191
+ if e .code is None :
192
+ # Fallback to 1 if there is no error code but a `SystemExit`.
193
+ return 1
194
+ try :
195
+ numeric_code = int (e .code )
196
+ return numeric_code
197
+ except ValueError :
198
+ # Fallback to 1 if it is an error message and print that message.
199
+ print (e )
200
+ return 1
201
+ finally :
202
+ # Fallback to 1 and do nothing, since there is only ValueError as
203
+ # expected exception.
204
+ return 1
205
+
206
+
185
207
# -----------------------------------------------------------------------------
186
208
# Argument Validation
187
209
@@ -719,7 +741,8 @@ if __name__ == "__main__":
719
741
try :
720
742
exit_code = main ()
721
743
except SystemExit as e :
722
- os ._exit (e .code )
744
+ error_code = process_system_exit (e )
745
+ os ._exit (error_code )
723
746
except KeyboardInterrupt :
724
747
sys .exit (1 )
725
748
finally :
You can’t perform that action at this time.
0 commit comments