From 2e05c234b62f22140fb853e246936f4f8b745d7f Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Sun, 3 Dec 2023 00:01:57 +0100 Subject: [PATCH] BackupErrors get caught and give warning RCs also: use more union operators rather than .union() --- scripts/errorlist.py | 8 ++++---- src/borg/helpers/errors.py | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/errorlist.py b/scripts/errorlist.py index dba19aae..8bc6f0bc 100755 --- a/scripts/errorlist.py +++ b/scripts/errorlist.py @@ -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 diff --git a/src/borg/helpers/errors.py b/src/borg/helpers/errors.py index 015dda1b..d19048a6 100644 --- a/src/borg/helpers/errors.py +++ b/src/borg/helpers/errors.py @@ -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.