changeset 34130:ada8a19672ab

debuginstall: do not pass exception object to formatter (issue5676)
author Yuya Nishihara <yuya@tcha.org>
date Thu, 07 Sep 2017 22:36:54 +0900
parents 902219a99901
children 0fa781320203
files mercurial/debugcommands.py tests/test-install.t
diffstat 2 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/debugcommands.py	Thu Sep 07 22:27:23 2017 +0900
+++ b/mercurial/debugcommands.py	Thu Sep 07 22:36:54 2017 +0900
@@ -1000,7 +1000,7 @@
     try:
         codecs.lookup(pycompat.sysstr(encoding.encoding))
     except LookupError as inst:
-        err = inst
+        err = util.forcebytestr(inst)
         problems += 1
     fm.condwrite(err, 'encodingerror', _(" %s\n"
                  " (check that your locale is properly set)\n"), err)
@@ -1056,7 +1056,7 @@
             )
             dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
         except Exception as inst:
-            err = inst
+            err = util.forcebytestr(inst)
             problems += 1
         fm.condwrite(err, 'extensionserror', " %s\n", err)
 
@@ -1088,7 +1088,7 @@
             try:
                 templater.templater.frommapfile(m)
             except Exception as inst:
-                err = inst
+                err = util.forcebytestr(inst)
                 p = None
             fm.condwrite(err, 'defaulttemplateerror', " %s\n", err)
         else:
@@ -1124,7 +1124,7 @@
     try:
         username = ui.username()
     except error.Abort as e:
-        err = e
+        err = util.forcebytestr(e)
         problems += 1
 
     fm.condwrite(username, 'username',  _("checking username (%s)\n"), username)
--- a/tests/test-install.t	Thu Sep 07 22:27:23 2017 +0900
+++ b/tests/test-install.t	Thu Sep 07 22:36:54 2017 +0900
@@ -81,6 +81,14 @@
   checking encoding (invalidenc)...
    unknown encoding: invalidenc
 
+exception message in JSON
+
+  $ HGENCODING=invalidenc HGUSER= hg debuginstall -Tjson | grep error
+    "defaulttemplateerror": null,
+    "encodingerror": "unknown encoding: invalidenc",
+    "extensionserror": null, (no-pure !)
+    "usernameerror": "no username supplied",
+
 path variables are expanded (~ is the same as $TESTTMP)
   $ mkdir tools
   $ touch tools/testeditor.exe