1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-22 07:43:06 +00:00

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 @@
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 @@ def subclasses(cls):
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 @@ def subclasses(cls):
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 @@
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 @@ def exit_code(self):
return self.exit_mcode if modern_ec else EXIT_ERROR
class Error(ErrorBase):
"""Error: {}"""
class ErrorWithTraceback(Error):
"""Error: {}"""
@ -122,7 +126,7 @@ def exit_code(self):
return exc.exit_mcode
class BackupError(Error):
class BackupError(ErrorBase):
"""{}: backup error"""
# Exception raised for non-OSError-based exceptions while accessing backup files.