Repository: borgbackup/borg

Issue:
Borg 1.1.x failing to handle exceptions for servers < 1.0.7
When `borg list server:repo` is run on version 1.0.11:

```
Remote: Borg 0.29.0: exception in RPC call:
Remote: Traceback (most recent call last):
Remote:   File "/usr/home/username/borgbackup-0.29.0/borg/remote.py", line 96, in serve
Remote: TypeError: open() takes from 2 to 5 positional arguments but 7 were given
Remote: Platform: FreeBSD servername.net 10.3-RELEASE FreeBSD 10.3-RELEASE #0: Wed Aug 30 20:40:07 CEST 2017     root@servername.net:/usr/src/sys/amd64/compile/servername_10.3 amd64
Remote: Python: CPython 3.4.3
Remote: 
Please note:
If you see a TypeError complaining about the number of positional arguments
given to open(), you can ignore it if it comes from a borg version < 1.0.7.
This TypeError is a cosmetic side effect of the compatibility code borg
clients >= 1.0.7 have to support older borg servers.
This problem will go away as soon as the server has been upgraded to 1.0.7+.
backup-2017-10-21T20:49:41.602262   Sat, 2017-10-21 20:49:49
backup-2017-10-23T10:44:59.177504   Mon, 2017-10-23 10:45:06
```

The same command run on version 1.1.1

```
Remote: Borg 0.29.0: exception in RPC call:
Remote: Traceback (most recent call last):
Remote:   File "/usr/home/username/borgbackup-0.29.0/borg/remote.py", line 96, in serve
Remote: TypeError: open() takes from 2 to 5 positional arguments but 7 were given
Remote: Platform: FreeBSD servername.net 10.3-RELEASE FreeBSD 10.3-RELEASE #0: Wed Aug 30 20:40:07 CEST 2017     root@servername.net:/usr/src/sys/amd64/compile/servername_10.3 amd64
Remote: Python: CPython 3.4.3
Remote: 
Please note:
If you see a TypeError complaining about the number of positional arguments
given to open(), you can ignore it if it comes from a borg version < 1.0.7.
This TypeError is a cosmetic side effect of the compatibility code borg
clients >= 1.0.7 have to support older borg servers.
This problem will go away as soon as the server has been upgraded to 1.0.7+.
Local Exception
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 591, in __init__
    do_open()
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 584, in do_open
    lock=lock, exclusive=exclusive, append_only=append_only)
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 476, in do_rpc
    return self.call(f.__name__, named, **extra)
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 707, in call
    for resp in self.call_many(cmd, [args], **kw):
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 773, in call_many
    handle_error(unpacked)
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 757, in handle_error
    raise self.RPCError(unpacked)
borg.remote.RemoteRepository.RPCError: {b'i': 2, b'exception_class': b'TypeError'}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/borg/archiver.py", line 4049, in main
    exit_code = archiver.run(args)
  File "/usr/lib/python3.6/site-packages/borg/archiver.py", line 3977, in run
    return set_ec(func(args))
  File "/usr/lib/python3.6/site-packages/borg/archiver.py", line 130, in wrapper
    lock_wait=self.lock_wait, lock=lock, append_only=append_only, args=args)
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 608, in __init__
    do_open()
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 584, in do_open
    lock=lock, exclusive=exclusive, append_only=append_only)
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 476, in do_rpc
    return self.call(f.__name__, named, **extra)
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 707, in call
    for resp in self.call_many(cmd, [args], **kw):
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 867, in call_many
    self.to_send = msgpack.packb((1, self.msgid, cmd, self.named_to_positional(cmd, args)))
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 704, in named_to_positional
    return [kwargs[name] for name in compatMap[method]]
  File "/usr/lib/python3.6/site-packages/borg/remote.py", line 704, in <listcomp>
    return [kwargs[name] for name in compatMap[method]]
KeyError: ('path', 'create', 'lock_wait', 'lock')

Platform: Linux mycomputer 4.13.8-1-ARCH #1 SMP PREEMPT Wed Oct 18 11:49:44 CEST 2017 x86_64 
Linux: arch  
Borg: 1.1.1  Python: CPython 3.6.3
PID: 23092  CWD: /root
sys.argv: ['/usr/bin/borg', 'list', 'server:repo']
SSH_ORIGINAL_COMMAND: None
```
I have also tested on 1.1.0. It seems all the 1.1.x branches have this issue.

Note: I'm connecting to the remote repo over SSH. In `~/.ssh/config` there is an entry called "server" that defines the HostName, User, and IdentityFile for the remote borg server.


Discussion:
You are using a borg 0.29 server?

I did not do compatibility testing for 1.1 against 0.xx because that is outdated anyway.

In case you are using rsync.net use `--remote-path=borg1` to get borg 1.x.

Hah, an evil trailing comma!
```
                    compatMap['open'] = ('path', 'create', 'lock_wait', 'lock', ),
```
@textshell ^

Resolving patch:
diff --git a/src/borg/remote.py b/src/borg/remote.py
--- a/src/borg/remote.py
+++ b/src/borg/remote.py
@@ -596,7 +596,7 @@ def do_open():
                     # emit this msg in the same way as the 'Remote: ...' lines that show the remote TypeError
                     sys.stderr.write(msg)
                     self.server_version = parse_version('1.0.6')
-                    compatMap['open'] = ('path', 'create', 'lock_wait', 'lock', ),
+                    compatMap['open'] = ('path', 'create', 'lock_wait', 'lock', )
                     # try again with corrected version and compatMap
                     do_open()
         except Exception:


Test patch: