error: add hint to ProgrammingError
authorYuya Nishihara <yuya@tcha.org>
Sun, 14 May 2017 15:41:27 +0900
changeset 32340 9c023179e8d0
parent 32339 92de09a05d7f
child 32341 b88d879e468a
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().
mercurial/dispatch.py
mercurial/error.py
tests/test-devel-warnings.t
--- 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