D4545: error: ensure ProgrammingError message is always a str
This revision was automatically updated to reflect the committed changes. Closed by commit rHG921aeb9ac508: error: ensure ProgrammingError message is always a str (authored by durin42, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4545?vs=10958=10959 REVISION DETAIL https://phab.mercurial-scm.org/D4545 AFFECTED FILES mercurial/error.py CHANGE DETAILS diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -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): To: durin42, #hg-reviewers, pulkit Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4545: error: ensure ProgrammingError message is always a str
durin42 updated this revision to Diff 10958. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4545?vs=10953=10958 REVISION DETAIL https://phab.mercurial-scm.org/D4545 AFFECTED FILES mercurial/error.py CHANGE DETAILS diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -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): To: durin42, #hg-reviewers, pulkit Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4545: error: ensure ProgrammingError message is always a str
durin42 created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY 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. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4545 AFFECTED FILES mercurial/error.py CHANGE DETAILS diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -215,6 +215,16 @@ class ProgrammingError(Hint, RuntimeError): """Raised if a mercurial (core or extension) developer made a mistake""" + +def __init__(self, msg): +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) + __bytes__ = _tobytes class WdirUnsupported(Exception): To: durin42, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel