فهرست منبع

PR #246 - Merge branch 'remote_exceptions' into merge

Thomas Waldmann 10 سال پیش
والد
کامیت
57b1b3dbec
2فایلهای تغییر یافته به همراه10 افزوده شده و 3 حذف شده
  1. 3 0
      attic/archiver.py
  2. 7 3
      attic/remote.py

+ 3 - 0
attic/archiver.py

@@ -750,6 +750,9 @@ def main():
     except Error as e:
         archiver.print_error(e.get_message())
         exit_code = e.exit_code
+    except RemoteRepository.RPCError as e:
+        print(e)
+        exit_code = 1
     except KeyboardInterrupt:
         archiver.print_error('Error: Keyboard interrupt')
         exit_code = 1

+ 7 - 3
attic/remote.py

@@ -7,6 +7,9 @@ import shutil
 from subprocess import Popen, PIPE
 import sys
 import tempfile
+import traceback
+
+from attic import __version__
 
 from .hashindex import NSIndex
 from .helpers import Error, IntegrityError
@@ -75,8 +78,9 @@ class RepositoryServer:
                         except AttributeError:
                             f = getattr(self.repository, method)
                         res = f(*args)
-                    except Exception as e:
-                        os.write(stdout_fd, msgpack.packb((1, msgid, e.__class__.__name__, e.args)))
+                    except BaseException as e:
+                        exc = "Remote Traceback by Attic %s%s%s" % (__version__, os.linesep, traceback.format_exc())
+                        os.write(stdout_fd, msgpack.packb((1, msgid, e.__class__.__name__, exc)))
                     else:
                         os.write(stdout_fd, msgpack.packb((1, msgid, None, res)))
             if es:
@@ -182,7 +186,7 @@ class RemoteRepository:
                             raise Repository.ObjectNotFound(res[0], self.location.orig)
                         elif error == b'InvalidRPCMethod':
                             raise InvalidRPCMethod(*res)
-                        raise self.RPCError(error)
+                        raise self.RPCError(res.decode('utf-8'))
                     else:
                         yield res
                         if not waiting_for and not calls: