Repository: borgbackup/borg

Issue:
non-intuitive exception chain on connection failure
this does not look very nice (exception within exception. and a full traceback instead of just nice message). a candidate for cleanup:

```
ssh: connect to host milhouse.podgorny.cz port 22: No route to host
borg: Error: Local Exception.
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/borg/remote.py", line 147, in __init__
    version = self.call('negotiate', 1)
  File "/usr/lib/python3.5/site-packages/borg/remote.py", line 176, in call
    for resp in self.call_many(cmd, [args], **kw):
  File "/usr/lib/python3.5/site-packages/borg/remote.py", line 226, in call_many
    raise ConnectionClosed()
borg.remote.ConnectionClosed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/borg/archiver.py", line 1030, in main
    exit_code = archiver.run(sys.argv[1:])
  File "/usr/lib/python3.5/site-packages/borg/archiver.py", line 986, in run
    return args.func(args)
  File "/usr/lib/python3.5/site-packages/borg/archiver.py", line 111, in do_create
    repository = self.open_repository(args.archive, exclusive=True)
  File "/usr/lib/python3.5/site-packages/borg/archiver.py", line 41, in open_repository
    repository = RemoteRepository(location, create=create)
  File "/usr/lib/python3.5/site-packages/borg/remote.py", line 149, in __init__
    raise Exception('Server immediately closed connection - is Borg installed and working on the server?')
Exception: Server immediately closed connection - is Borg installed and working on the server?

borg: Exiting with failure status due to previous errors
```



Discussion:
I agree it doesn't look nice, but we must be careful to not lose information while making it look prettier.
Analyzing some attic issues has been a real pain just because it did not emit enough information.

yep, sure thing. but i was just surprised as the server is currently down and the message says something about borg not being installed on the remote end. so i wanted to let you know it's a bit misleading...

well, the phrasing is "installed and working". If the server is down, it obviously not "working".

but I agree we could omit the "installed" part. borg is not working if it is not installed. borg is not working if the server is down. and you will notice the server is down when you check whether borg is working there.

i thought about replacing "working" with "running", but as this is not a permanent server process, we can't say "running".

btw, this is somehow part of the more general issue #57.


Resolving patch:
diff --git a/borg/remote.py b/borg/remote.py
--- a/borg/remote.py
+++ b/borg/remote.py
@@ -23,6 +23,10 @@ class ConnectionClosed(Error):
     """Connection closed by remote host"""
 
 
+class ConnectionClosedWithHint(ConnectionClosed):
+    """Connection closed by remote host. {}"""
+
+
 class PathNotAllowed(Error):
     """Repository path not allowed"""
 
@@ -148,7 +152,7 @@ def __init__(self, location, create=False):
         try:
             version = self.call('negotiate', 1)
         except ConnectionClosed:
-            raise Exception('Server immediately closed connection - is Borg installed and working on the server?')
+            raise ConnectionClosedWithHint('Is borg working on the server?')
         if version != 1:
             raise Exception('Server insisted on using unsupported protocol version %d' % version)
         self.id = self.call('open', location.path, create)


Test patch: