changeset 39579:921aeb9ac508

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
author Augie Fackler <augie@google.com>
date Wed, 12 Sep 2018 11:37:34 -0400
parents b781709799f6
children a64a965b3610
files mercurial/error.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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):