error: add hint to ProgrammingError
As the hint isn't shown by the default exception handler, we need to print
it manually. I've copied the "** " style from _exceptionwarning().
--- a/mercurial/dispatch.py Mon May 08 22:14:56 2017 +0900
+++ b/mercurial/dispatch.py Sun May 14 15:41:27 2017 +0900
@@ -162,6 +162,11 @@
ret = None
try:
ret = _runcatch(req)
+ except error.ProgrammingError as inst:
+ req.ui.warn(_('** ProgrammingError: %s\n') % inst)
+ if inst.hint:
+ req.ui.warn(_('** (%s)\n') % inst.hint)
+ raise
except KeyboardInterrupt as inst:
try:
if isinstance(inst, error.SignalInterrupt):
--- a/mercurial/error.py Mon May 08 22:14:56 2017 +0900
+++ b/mercurial/error.py Sun May 14 15:41:27 2017 +0900
@@ -174,7 +174,7 @@
class PushRaced(RuntimeError):
"""An exception raised during unbundling that indicate a push race"""
-class ProgrammingError(RuntimeError):
+class ProgrammingError(Hint, RuntimeError):
"""Raised if a mercurial (core or extension) developer made a mistake"""
# bundle2 related errors
--- a/tests/test-devel-warnings.t Mon May 08 22:14:56 2017 +0900
+++ b/tests/test-devel-warnings.t Sun May 14 15:41:27 2017 +0900
@@ -3,7 +3,7 @@
> """A small extension that tests our developer warnings
> """
>
- > from mercurial import registrar, repair, util
+ > from mercurial import error, registrar, repair, util
>
> cmdtable = {}
> command = registrar.command(cmdtable)
@@ -61,6 +61,9 @@
> @command('nouiwarning', [], '')
> def nouiwarning(ui, repo):
> util.nouideprecwarn('this is a test', '13.37')
+ > @command('programmingerror', [], '')
+ > def programmingerror(ui, repo):
+ > raise error.ProgrammingError('something went wrong', hint='try again')
> EOF
$ cat << EOF >> $HGRCPATH
@@ -163,9 +166,23 @@
** Python * (glob)
** Mercurial Distributed SCM (*) (glob)
** Extensions loaded: * (glob)
+ ** ProgrammingError: transaction requires locking
Traceback (most recent call last):
mercurial.error.ProgrammingError: transaction requires locking
+ $ hg programmingerror 2>&1 | egrep -v '^ '
+ ** Unknown exception encountered with possibly-broken third-party extension buggylocking
+ ** which supports versions unknown of Mercurial.
+ ** Please disable buggylocking and try your action again.
+ ** If that fixes the bug please report it to the extension author.
+ ** Python * (glob)
+ ** Mercurial Distributed SCM (*) (glob)
+ ** Extensions loaded: * (glob)
+ ** ProgrammingError: something went wrong
+ ** (try again)
+ Traceback (most recent call last):
+ mercurial.error.ProgrammingError: something went wrong
+
Old style deprecation warning
$ hg nouiwarning