1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 09:19:31 +00:00

Merge pull request #349 from ThomasWaldmann/pretty-errors

prettier error messages, fixes #57
This commit is contained in:
TW 2015-10-31 22:44:04 +01:00
commit 5f86959762
7 changed files with 25 additions and 20 deletions

View file

@ -1064,7 +1064,9 @@ def main(): # pragma: no cover
msg = None msg = None
exit_code = archiver.run(sys.argv[1:]) exit_code = archiver.run(sys.argv[1:])
except Error as e: 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 exit_code = e.exit_code
except RemoteRepository.RPCError as e: except RemoteRepository.RPCError as e:
msg = 'Remote Exception.\n%s' % str(e) msg = 'Remote Exception.\n%s' % str(e)

View file

@ -35,8 +35,7 @@ class RepositoryAccessAborted(Error):
"""Repository access aborted""" """Repository access aborted"""
class EncryptionMethodMismatch(Error): 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): def __init__(self, repository, key, manifest, path=None, sync=True, do_files=False, warn_if_unencrypted=True):
self.lock = None self.lock = None

View file

@ -60,12 +60,19 @@ class Error(Exception):
# exception handler (that exits short after with the given exit_code), # exception handler (that exits short after with the given exit_code),
# it is always a (fatal and abrupt) EXIT_ERROR, never just a warning. # it is always a (fatal and abrupt) EXIT_ERROR, never just a warning.
exit_code = EXIT_ERROR exit_code = EXIT_ERROR
# show a traceback?
traceback = False
def get_message(self): def get_message(self):
return type(self).__doc__.format(*self.args) 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""" """Data integrity error"""

View file

@ -19,18 +19,15 @@
class UnsupportedPayloadError(Error): 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): class KeyfileNotFoundError(Error):
"""No key file for repository {} found in {}. """No key file for repository {} found in {}."""
"""
class RepoKeyNotFoundError(Error): 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): class HMAC(hmac.HMAC):

View file

@ -4,7 +4,7 @@
import socket import socket
import time import time
from borg.helpers import Error from borg.helpers import Error, ErrorWithTraceback
ADD, REMOVE = 'add', 'remove' ADD, REMOVE = 'add', 'remove'
SHARED, EXCLUSIVE = 'shared', 'exclusive' SHARED, EXCLUSIVE = 'shared', 'exclusive'
@ -76,7 +76,7 @@ def timed_out_or_sleep(self):
class ExclusiveLock: class ExclusiveLock:
"""An exclusive Lock based on mkdir fs operation being atomic""" """An exclusive Lock based on mkdir fs operation being atomic"""
class LockError(Error): class LockError(ErrorWithTraceback):
"""Failed to acquire the lock {}.""" """Failed to acquire the lock {}."""
class LockTimeout(LockError): class LockTimeout(LockError):
@ -85,7 +85,7 @@ class LockTimeout(LockError):
class LockFailed(LockError): class LockFailed(LockError):
"""Failed to create/acquire the lock {} ({}).""" """Failed to create/acquire the lock {} ({})."""
class UnlockError(Error): class UnlockError(ErrorWithTraceback):
"""Failed to release the lock {}.""" """Failed to release the lock {}."""
class NotLocked(UnlockError): class NotLocked(UnlockError):
@ -215,10 +215,10 @@ class UpgradableLock:
noone is allowed reading) and read access to a resource needs a shared noone is allowed reading) and read access to a resource needs a shared
lock (multiple readers are allowed). lock (multiple readers are allowed).
""" """
class SharedLockFailed(Error): class SharedLockFailed(ErrorWithTraceback):
"""Failed to acquire shared lock [{}]""" """Failed to acquire shared lock [{}]"""
class ExclusiveLockFailed(Error): class ExclusiveLockFailed(ErrorWithTraceback):
"""Failed to acquire write lock [{}]""" """Failed to acquire write lock [{}]"""
def __init__(self, path, exclusive=False, sleep=None, id=None): def __init__(self, path, exclusive=False, sleep=None, id=None):

View file

@ -28,7 +28,7 @@ class PathNotAllowed(Error):
class InvalidRPCMethod(Error): class InvalidRPCMethod(Error):
"""RPC method is not valid""" """RPC method {} is not valid"""
class RepositoryServer: # pragma: no cover class RepositoryServer: # pragma: no cover

View file

@ -11,7 +11,7 @@
import sys import sys
from zlib import crc32 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(): if have_cython():
from .hashindex import NSIndex from .hashindex import NSIndex
from .locking import UpgradableLock from .locking import UpgradableLock
@ -45,12 +45,12 @@ class AlreadyExists(Error):
"""Repository {} already exists.""" """Repository {} already exists."""
class InvalidRepository(Error): 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 {}".""" """Inconsistency detected. Please run "borg check {}"."""
class ObjectNotFound(Error): class ObjectNotFound(ErrorWithTraceback):
"""Object with key {} not found in repository {}.""" """Object with key {} not found in repository {}."""
def __init__(self, path, create=False, exclusive=False): def __init__(self, path, create=False, exclusive=False):