diff --git a/borg/archiver.py b/borg/archiver.py index 3ab156951..3fdad7dfd 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -1062,7 +1062,9 @@ def main(): # pragma: no cover msg = None exit_code = archiver.run(sys.argv[1:]) except Error as e: - msg = e.get_message() + "\n%s" % traceback.format_exc() + msg = e.get_message() + if e.traceback: + msg += "\n%s" % traceback.format_exc() exit_code = e.exit_code except RemoteRepository.RPCError as e: msg = 'Remote Exception.\n%s' % str(e) diff --git a/borg/cache.py b/borg/cache.py index 729149c21..436c625ae 100644 --- a/borg/cache.py +++ b/borg/cache.py @@ -35,8 +35,7 @@ class Cache: """Repository access aborted""" class EncryptionMethodMismatch(Error): - """Repository encryption method changed since last acccess, refusing to continue - """ + """Repository encryption method changed since last access, refusing to continue""" def __init__(self, repository, key, manifest, path=None, sync=True, do_files=False, warn_if_unencrypted=True): self.lock = None diff --git a/borg/helpers.py b/borg/helpers.py index c9ffc00b7..90e0ec19a 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -58,12 +58,19 @@ class Error(Exception): # 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 + # show a traceback? + traceback = False def get_message(self): return type(self).__doc__.format(*self.args) -class IntegrityError(Error): +class ErrorWithTraceback(Error): + """like Error, but show a traceback also""" + traceback = True + + +class IntegrityError(ErrorWithTraceback): """Data integrity error""" diff --git a/borg/key.py b/borg/key.py index a9ceef41d..43f6c5cad 100644 --- a/borg/key.py +++ b/borg/key.py @@ -19,18 +19,15 @@ PREFIX = b'\0' * 8 class UnsupportedPayloadError(Error): - """Unsupported payload type {}. A newer version is required to access this repository. - """ + """Unsupported payload type {}. A newer version is required to access this repository.""" class KeyfileNotFoundError(Error): - """No key file for repository {} found in {}. - """ + """No key file for repository {} found in {}.""" class RepoKeyNotFoundError(Error): - """No key entry found in the config of repository {}. - """ + """No key entry found in the config of repository {}.""" class HMAC(hmac.HMAC): diff --git a/borg/locking.py b/borg/locking.py index aff3c5fcd..159e3c57e 100644 --- a/borg/locking.py +++ b/borg/locking.py @@ -4,7 +4,7 @@ import os import socket import time -from borg.helpers import Error +from borg.helpers import Error, ErrorWithTraceback ADD, REMOVE = 'add', 'remove' SHARED, EXCLUSIVE = 'shared', 'exclusive' @@ -76,7 +76,7 @@ class TimeoutTimer: class ExclusiveLock: """An exclusive Lock based on mkdir fs operation being atomic""" - class LockError(Error): + class LockError(ErrorWithTraceback): """Failed to acquire the lock {}.""" class LockTimeout(LockError): @@ -85,7 +85,7 @@ class ExclusiveLock: class LockFailed(LockError): """Failed to create/acquire the lock {} ({}).""" - class UnlockError(Error): + class UnlockError(ErrorWithTraceback): """Failed to release the lock {}.""" class NotLocked(UnlockError): @@ -215,10 +215,10 @@ class UpgradableLock: noone is allowed reading) and read access to a resource needs a shared lock (multiple readers are allowed). """ - class SharedLockFailed(Error): + class SharedLockFailed(ErrorWithTraceback): """Failed to acquire shared lock [{}]""" - class ExclusiveLockFailed(Error): + class ExclusiveLockFailed(ErrorWithTraceback): """Failed to acquire write lock [{}]""" def __init__(self, path, exclusive=False, sleep=None, id=None): diff --git a/borg/remote.py b/borg/remote.py index 5d8c71a88..cffa62d78 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -28,7 +28,7 @@ class PathNotAllowed(Error): class InvalidRPCMethod(Error): - """RPC method is not valid""" + """RPC method {} is not valid""" class RepositoryServer: # pragma: no cover diff --git a/borg/repository.py b/borg/repository.py index 69ced28de..acb57e0d5 100644 --- a/borg/repository.py +++ b/borg/repository.py @@ -11,7 +11,7 @@ import struct import sys from zlib import crc32 -from .helpers import Error, IntegrityError, read_msgpack, write_msgpack, unhexlify, have_cython +from .helpers import Error, ErrorWithTraceback, IntegrityError, read_msgpack, write_msgpack, unhexlify, have_cython if have_cython(): from .hashindex import NSIndex from .locking import UpgradableLock @@ -45,12 +45,12 @@ class Repository: """Repository {} already exists.""" class InvalidRepository(Error): - """{} is not a valid repository.""" + """{} is not a valid repository. Check repo config.""" - class CheckNeeded(Error): + class CheckNeeded(ErrorWithTraceback): """Inconsistency detected. Please run "borg check {}".""" - class ObjectNotFound(Error): + class ObjectNotFound(ErrorWithTraceback): """Object with key {} not found in repository {}.""" def __init__(self, path, create=False, exclusive=False):