|
@@ -1,3 +1,5 @@
|
|
|
+import os
|
|
|
+
|
|
|
from ..constants import * # NOQA
|
|
|
|
|
|
from ..crypto.low_level import IntegrityError as IntegrityErrorBase
|
|
@@ -10,8 +12,9 @@ class Error(Exception):
|
|
|
|
|
|
# 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),
|
|
|
- # it is always a (fatal and abrupt) EXIT_ERROR, never just a warning.
|
|
|
- exit_code = EXIT_ERROR
|
|
|
+ # it is always a (fatal and abrupt) error, never just a warning.
|
|
|
+ exit_mcode = EXIT_ERROR # modern, more specific exit code (defaults to EXIT_ERROR)
|
|
|
+
|
|
|
# show a traceback?
|
|
|
traceback = False
|
|
|
|
|
@@ -24,6 +27,13 @@ class Error(Exception):
|
|
|
|
|
|
__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):
|
|
|
"""Error: {}"""
|