changeset 39596:409c42d6a570

py3: use sysstr() to convert ProgrammingError bytes with no unicode error risk msg.decode('utf8') may fail if msg isn't an ASCII string, and that's possible as we sometimes embed a filename in the error message for example.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 13 Sep 2018 22:32:51 +0900
parents a911932d5003
children 164827563426
files mercurial/error.py
diffstat 1 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/error.py	Mon Sep 10 08:31:41 2018 +0200
+++ b/mercurial/error.py	Thu Sep 13 22:32:51 2018 +0900
@@ -217,12 +217,10 @@
     """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')
+        # On Python 3, 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 = pycompat.sysstr(msg)
         super(ProgrammingError, self).__init__(msg, *args, **kwargs)
 
     __bytes__ = _tobytes