comparison mercurial/error.py @ 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 921aeb9ac508
children cb65d4b7e429
comparison
equal deleted inserted replaced
39595:a911932d5003 39596:409c42d6a570
215 215
216 class ProgrammingError(Hint, RuntimeError): 216 class ProgrammingError(Hint, RuntimeError):
217 """Raised if a mercurial (core or extension) developer made a mistake""" 217 """Raised if a mercurial (core or extension) developer made a mistake"""
218 218
219 def __init__(self, msg, *args, **kwargs): 219 def __init__(self, msg, *args, **kwargs):
220 if not isinstance(msg, str): 220 # On Python 3, turn the message back into a string since this is
221 # This means we're on Python 3, because we got a 221 # an internal-only error that won't be printed except in a
222 # bytes. Turn the message back into a string since this is 222 # stack traces.
223 # an internal-only error that won't be printed except in a 223 msg = pycompat.sysstr(msg)
224 # stack traces.
225 msg = msg.decode('utf8')
226 super(ProgrammingError, self).__init__(msg, *args, **kwargs) 224 super(ProgrammingError, self).__init__(msg, *args, **kwargs)
227 225
228 __bytes__ = _tobytes 226 __bytes__ = _tobytes
229 227
230 class WdirUnsupported(Exception): 228 class WdirUnsupported(Exception):