From 900a1674dfdabdf31e31c30a5dd94be159ca0677 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 15 Nov 2023 18:04:54 +0100 Subject: [PATCH] move Backup*Error to errors module --- src/borg/archive.py | 38 +----------------------------------- src/borg/helpers/__init__.py | 1 + src/borg/helpers/errors.py | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/borg/archive.py b/src/borg/archive.py index a1c7602ce..e8ce53fc1 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -26,6 +26,7 @@ from .crypto.key import key_factory, UnsupportedPayloadError from .compress import CompressionSpec from .constants import * # NOQA from .crypto.low_level import IntegrityError as IntegrityErrorBase +from .helpers import BackupError, BackupOSError, BackupRaceConditionError from .hashindex import ChunkIndex, ChunkIndexEntry, CacheSynchronizer from .helpers import HardLinkManager from .helpers import ChunkIteratorFileWrapper, open_item @@ -181,43 +182,6 @@ def is_special(mode): return stat.S_ISBLK(mode) or stat.S_ISCHR(mode) or stat.S_ISFIFO(mode) -class BackupError(Exception): - """ - Exception raised for non-OSError-based exceptions while accessing backup files. - """ - - -class BackupRaceConditionError(BackupError): - """ - Exception raised when encountering a critical race condition while trying to back up a file. - """ - - -class BackupOSError(Exception): - """ - Wrapper for OSError raised while accessing backup files. - - Borg does different kinds of IO, and IO failures have different consequences. - This wrapper represents failures of input file or extraction IO. - These are non-critical and are only reported (exit code = 1, warning). - - Any unwrapped IO error is critical and aborts execution (for example repository IO failure). - """ - - def __init__(self, op, os_error): - self.op = op - self.os_error = os_error - self.errno = os_error.errno - self.strerror = os_error.strerror - self.filename = os_error.filename - - def __str__(self): - if self.op: - return f"{self.op}: {self.os_error}" - else: - return str(self.os_error) - - class BackupIO: op = "" diff --git a/src/borg/helpers/__init__.py b/src/borg/helpers/__init__.py index 7970b1fcd..d898fe095 100644 --- a/src/borg/helpers/__init__.py +++ b/src/borg/helpers/__init__.py @@ -14,6 +14,7 @@ from .datastruct import StableDict, Buffer, EfficientCollectionQueue from .errors import Error, ErrorWithTraceback, IntegrityError, DecompressionError, CancelledByUser, CommandError from .errors import RTError, modern_ec from .errors import BorgWarning, FileChangedWarning, BackupExcWarning, IncludePatternNeverMatchedWarning +from .errors import BackupError, BackupOSError, BackupRaceConditionError from .fs import ensure_dir, join_base_dir, get_socket_filename from .fs import get_security_dir, get_keys_dir, get_base_dir, get_cache_dir, get_config_dir, get_runtime_dir from .fs import dir_is_tagged, dir_is_cachedir, remove_dotdot_prefixes, make_path_safe, scandir_inorder diff --git a/src/borg/helpers/errors.py b/src/borg/helpers/errors.py index 85a620849..24917a0a6 100644 --- a/src/borg/helpers/errors.py +++ b/src/borg/helpers/errors.py @@ -114,3 +114,40 @@ class BackupExcWarning(BorgWarning): exit_mcode = 102 # TODO: override exit_code and compute the exit code based on the wrapped exception. + + +class BackupError(Exception): + """ + Exception raised for non-OSError-based exceptions while accessing backup files. + """ + + +class BackupRaceConditionError(BackupError): + """ + Exception raised when encountering a critical race condition while trying to back up a file. + """ + + +class BackupOSError(Exception): + """ + Wrapper for OSError raised while accessing backup files. + + Borg does different kinds of IO, and IO failures have different consequences. + This wrapper represents failures of input file or extraction IO. + These are non-critical and are only reported (exit code = 1, warning). + + Any unwrapped IO error is critical and aborts execution (for example repository IO failure). + """ + + def __init__(self, op, os_error): + self.op = op + self.os_error = os_error + self.errno = os_error.errno + self.strerror = os_error.strerror + self.filename = os_error.filename + + def __str__(self): + if self.op: + return f"{self.op}: {self.os_error}" + else: + return str(self.os_error)