changeset 39486:43d92d68ac88

wireprotov2peer: properly format errors formatrichmessage() expects an iterable containing dicts with well-defined keys. We were passing in something else. This caused an exception. Change the code to call formatrichmessage() with the proper argument. And add a TODO to potentially emit the proper data structure from the server in the first place. Differential Revision: https://phab.mercurial-scm.org/D4441
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 05 Sep 2018 09:04:40 -0700
parents 42bc1c70a6b8
children 931386a0b108
files mercurial/wireprotoframing.py mercurial/wireprotov2peer.py
diffstat 2 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/wireprotoframing.py	Thu Aug 23 13:50:47 2018 -0700
+++ b/mercurial/wireprotoframing.py	Wed Sep 05 09:04:40 2018 -0700
@@ -419,6 +419,8 @@
                            payload=b'')
 
 def createcommanderrorresponse(stream, requestid, message, args=None):
+    # TODO should this be using a list of {'msg': ..., 'args': {}} so atom
+    # formatting works consistently?
     m = {
         b'status': b'error',
         b'error': {
--- a/mercurial/wireprotov2peer.py	Thu Aug 23 13:50:47 2018 -0700
+++ b/mercurial/wireprotov2peer.py	Wed Sep 05 09:04:40 2018 -0700
@@ -27,7 +27,7 @@
         msg = _(atom[b'msg'])
 
         if b'args' in atom:
-            msg = msg % atom[b'args']
+            msg = msg % tuple(atom[b'args'])
 
         chunks.append(msg)
 
@@ -163,8 +163,10 @@
                 if overall['status'] == 'ok':
                     self._futures[frame.requestid].set_result(decoder(objs))
                 else:
-                    e = error.RepoError(
-                        formatrichmessage(overall['error']['message']))
+                    atoms = [{'msg': overall['error']['message']}]
+                    if 'args' in overall['error']:
+                        atoms[0]['args'] = overall['error']['args']
+                    e = error.RepoError(formatrichmessage(atoms))
                     self._futures[frame.requestid].set_exception(e)
             else:
                 self._futures[frame.requestid].set_result(response)