D4441: wireprotov2peer: properly format errors

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Fri Aug 31 22:57:23 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4441

AFFECTED FILES
  mercurial/wireprotoframing.py
  mercurial/wireprotov2peer.py

CHANGE DETAILS

diff --git a/mercurial/wireprotov2peer.py b/mercurial/wireprotov2peer.py
--- a/mercurial/wireprotov2peer.py
+++ b/mercurial/wireprotov2peer.py
@@ -166,8 +166,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)
diff --git a/mercurial/wireprotoframing.py b/mercurial/wireprotoframing.py
--- a/mercurial/wireprotoframing.py
+++ b/mercurial/wireprotoframing.py
@@ -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': {



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list