From 425a4d819d39f2e5f601e2822e7a427eca2d2058 Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Mon, 4 Apr 2016 17:09:52 +0200 Subject: [PATCH 1/2] Remote: don't print tracebacks for Error exceptions handled downstream (What we'd really want is to have proper exception transporting over the RPC) Fixes #792 --- borg/remote.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/borg/remote.py b/borg/remote.py index b91a4f95e..af74c69d8 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -93,8 +93,12 @@ class RepositoryServer: # pragma: no cover f = getattr(self.repository, method) res = f(*args) except BaseException as e: - logging.exception('Borg %s: exception in RPC call:', __version__) - logging.error(sysinfo()) + # These exceptions are reconstructed on the client end in RemoteRepository.call_many(), + # and will be handled just like locally raised exceptions. Suppress the remote traceback + # for these, except ErrorWithTraceback, which should always display a traceback. + if not isinstance(e, (Repository.DoesNotExist, Repository.AlreadyExists, PathNotAllowed)): + logging.exception('Borg %s: exception in RPC call:', __version__) + logging.error(sysinfo()) exc = "Remote Exception (see remote log for the traceback)" os.write(stdout_fd, msgpack.packb((1, msgid, e.__class__.__name__, exc))) else: From 890e44ef60a9a90ee6aab60e3ece2b6b3159e0bb Mon Sep 17 00:00:00 2001 From: Marian Beermann Date: Sun, 3 Apr 2016 21:44:29 +0200 Subject: [PATCH 2/2] RemoteRepository: clean up pipe if remote open() fails --- borg/remote.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/borg/remote.py b/borg/remote.py index af74c69d8..30a343922 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -81,6 +81,7 @@ class RepositoryServer: # pragma: no cover unpacker.feed(data) for unpacked in unpacker: if not (isinstance(unpacked, tuple) and len(unpacked) == 4): + self.repository.close() raise Exception("Unexpected RPC data format.") type, msgid, method, args = unpacked method = method.decode('ascii') @@ -165,7 +166,11 @@ class RemoteRepository: raise ConnectionClosedWithHint('Is borg working on the server?') from None if version != RPC_PROTOCOL_VERSION: raise Exception('Server insisted on using unsupported protocol version %d' % version) - self.id = self.call('open', location.path, create, lock_wait, lock) + try: + self.id = self.call('open', self.location.path, create, lock_wait, lock) + except Exception: + self.close() + raise def __del__(self): self.close()