Patchwork [2,of,2] debuginstall: do not pass exception object to formatter (issue5676)

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 7, 2017, 1:54 p.m.
Message ID <3573b95ec1f32805bde3.1504792469@mimosa>
Download mbox | patch
Permalink /patch/23717/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 7, 2017, 1:54 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1504791414 -32400
#      Thu Sep 07 22:36:54 2017 +0900
# Node ID 3573b95ec1f32805bde3a08b1f4f7dca8e3d699f
# Parent  5fda73a5468d3789bccdcb2da6d6b56e5ca2410b
debuginstall: do not pass exception object to formatter (issue5676)
Augie Fackler - Sept. 13, 2017, 2:42 a.m.
On Thu, Sep 07, 2017 at 10:54:29PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1504791414 -32400
> #      Thu Sep 07 22:36:54 2017 +0900
> # Node ID 3573b95ec1f32805bde3a08b1f4f7dca8e3d699f
> # Parent  5fda73a5468d3789bccdcb2da6d6b56e5ca2410b
> debuginstall: do not pass exception object to formatter (issue5676)

queued, thanks

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1000,7 +1000,7 @@  def debuginstall(ui, **opts):
     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 @@  def debuginstall(ui, **opts):
             )
             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 @@  def debuginstall(ui, **opts):
             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 @@  def debuginstall(ui, **opts):
     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)
diff --git a/tests/test-install.t b/tests/test-install.t
--- a/tests/test-install.t
+++ b/tests/test-install.t
@@ -81,6 +81,14 @@  hg debuginstall with invalid encoding
   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