error: ensure ProgrammingError message is always a str
authorAugie Fackler <augie@google.com>
Wed, 12 Sep 2018 11:37:34 -0400
changeset 39579 921aeb9ac508
parent 39578 b781709799f6
child 39580 a64a965b3610
error: ensure ProgrammingError message is always a str Since this error is internal-only and a runtime error, let's give it a treatment that makes it behave identically when repr()d on both Python 2 and Python 3. Differential Revision: https://phab.mercurial-scm.org/D4545
mercurial/error.py
--- a/mercurial/error.py	Wed Sep 12 11:39:48 2018 -0400
+++ b/mercurial/error.py	Wed Sep 12 11:37:34 2018 -0400
@@ -215,6 +215,16 @@
 
 class ProgrammingError(Hint, RuntimeError):
     """Raised if a mercurial (core or extension) developer made a mistake"""
+
+    def __init__(self, msg, *args, **kwargs):
+        if not isinstance(msg, str):
+            # This means we're on Python 3, because we got a
+            # bytes. Turn the message back into a string since this is
+            # an internal-only error that won't be printed except in a
+            # stack traces.
+            msg = msg.decode('utf8')
+        super(ProgrammingError, self).__init__(msg, *args, **kwargs)
+
     __bytes__ = _tobytes
 
 class WdirUnsupported(Exception):