# HG changeset patch # User Yuya Nishihara # Date 2018-09-13 13:32:51 # Node ID 409c42d6a5705ebaf33850ea4e91667b06ee903e # Parent a911932d500311eb6cbe8ec8cbab435547cebfa0 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. diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -217,12 +217,10 @@ class ProgrammingError(Hint, RuntimeErro """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