BackupErrors get caught and give warning RCs

also: use more union operators rather than .union()
This commit is contained in:
Thomas Waldmann 2023-12-03 00:01:57 +01:00
parent 97dd287584
commit 2e05c234b6
No known key found for this signature in database
GPG Key ID: 243ACFA951F78E01
2 changed files with 11 additions and 7 deletions

View File

@ -6,12 +6,12 @@ from textwrap import indent
import borg.archiver # noqa: F401 - need import to get Error subclasses.
from borg.constants import * # NOQA
from borg.helpers import Error, BorgWarning
from borg.helpers import Error, BackupError, BorgWarning
def subclasses(cls):
direct_subclasses = cls.__subclasses__()
return set(direct_subclasses).union([s for c in direct_subclasses for s in subclasses(c)])
return set(direct_subclasses) | set(s for c in direct_subclasses for s in subclasses(c))
# 0, 1, 2 are used for success, generic warning, generic error
@ -25,7 +25,7 @@ free_warning_rcs = set(range(EXIT_WARNING_BASE, EXIT_SIGNAL_BASE)) # 100 .. 127
generic_error_rc_classes = set()
generic_warning_rc_classes = set()
error_classes = {Error}.union(subclasses(Error))
error_classes = {Error} | subclasses(Error)
for cls in sorted(error_classes, key=lambda cls: (cls.__module__, cls.__qualname__)):
traceback = "yes" if cls.traceback else "no"
@ -44,7 +44,7 @@ print()
print("free error RCs:", sorted(free_error_rcs))
print("generic errors:", sorted(generic_error_rc_classes))
warning_classes = {BorgWarning}.union(subclasses(BorgWarning))
warning_classes = {BorgWarning} | subclasses(BorgWarning) | {BackupError} | subclasses(BackupError)
for cls in sorted(warning_classes, key=lambda cls: (cls.__module__, cls.__qualname__)):
rc = cls.exit_mcode

View File

@ -8,8 +8,8 @@ from ..crypto.low_level import IntegrityError as IntegrityErrorBase
modern_ec = os.environ.get("BORG_EXIT_CODES", "legacy") == "modern"
class Error(Exception):
"""Error: {}"""
class ErrorBase(Exception):
"""ErrorBase: {}"""
# Error base class
@ -37,6 +37,10 @@ class Error(Exception):
return self.exit_mcode if modern_ec else EXIT_ERROR
class Error(ErrorBase):
"""Error: {}"""
class ErrorWithTraceback(Error):
"""Error: {}"""
@ -122,7 +126,7 @@ class BackupWarning(BorgWarning):
return exc.exit_mcode
class BackupError(Error):
class BackupError(ErrorBase):
"""{}: backup error"""
# Exception raised for non-OSError-based exceptions while accessing backup files.