Returning the intended exit code from the main try block that invokes the
subcommand handler rather than trying to exit within the exception handling
seems to work better and actually return the error code.
Signed-off-by: David Howells <dhowells@redhat.com>
try:
command.main(params)
ret = get_exitcode()
- sys.exit(ret)
except (AFSException, IOError) as err:
print(prog + ":", str(err), file=sys.stderr)
if debugging_level > 0:
traceback.print_exc()
- sys.exit(1)
+ ret = 1
except AFSArgumentError as e:
print(prog + ":", e, file=sys.stderr)
- sys.exit(2)
+ ret = 2
except KeyboardInterrupt:
- sys.exit(1)
+ ret = 1
except SystemExit:
- sys.exit(0)
+ ret = 0
except:
print('Unhandled exception:', file=sys.stderr)
traceback.print_exc()
- sys.exit(3)
+ ret = 3
sys.exit(ret or 0)