mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-02 04:24:34 +00:00
BORG_EXIT_CODES=modern can be set to get more specific process exit codes
If not set, it will default to "legacy" (always return 2 for errors). This commit only changes the Error exception class and its subclasses. The more specific exit codes need to be defined via .exit_mcode in the subclasses.
This commit is contained in:
parent
94c461974d
commit
2a13268e05
1 changed files with 12 additions and 2 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
from ..constants import * # NOQA
|
from ..constants import * # NOQA
|
||||||
|
|
||||||
import borg.crypto.low_level
|
import borg.crypto.low_level
|
||||||
|
@ -9,8 +11,9 @@ class Error(Exception):
|
||||||
|
|
||||||
# if we raise such an Error and it is only caught by the uppermost
|
# if we raise such an Error and it is only caught by the uppermost
|
||||||
# exception handler (that exits short after with the given exit_code),
|
# exception handler (that exits short after with the given exit_code),
|
||||||
# it is always a (fatal and abrupt) EXIT_ERROR, never just a warning.
|
# it is always a (fatal and abrupt) error, never just a warning.
|
||||||
exit_code = EXIT_ERROR
|
exit_mcode = EXIT_ERROR # modern, more specific exit code (defaults to EXIT_ERROR)
|
||||||
|
|
||||||
# show a traceback?
|
# show a traceback?
|
||||||
traceback = False
|
traceback = False
|
||||||
|
|
||||||
|
@ -23,6 +26,13 @@ def get_message(self):
|
||||||
|
|
||||||
__str__ = get_message
|
__str__ = get_message
|
||||||
|
|
||||||
|
@property
|
||||||
|
def exit_code(self):
|
||||||
|
# legacy: borg used to always use rc 2 (EXIT_ERROR) for all errors.
|
||||||
|
# modern: users can opt in to more specific return codes, using BORG_RC_STYLE:
|
||||||
|
modern = os.environ.get("BORG_EXIT_CODES", "legacy") == "modern"
|
||||||
|
return self.exit_mcode if modern else EXIT_ERROR
|
||||||
|
|
||||||
|
|
||||||
class ErrorWithTraceback(Error):
|
class ErrorWithTraceback(Error):
|
||||||
"""Error: {}"""
|
"""Error: {}"""
|
||||||
|
|
Loading…
Reference in a new issue