changeset 43402:40bf3d7ecc42 stable

py3: add a __str__ method to Abort This improves the rendering of some exceptions by avoiding raw bytestrings, especially when using --traceback option.
author Denis Laxalde <denis@laxalde.org>
date Mon, 04 Nov 2019 16:13:01 +0100
parents 09537caa87f9
children 90fba2248693
files mercurial/error.py tests/test-flagprocessor.t tests/test-hook.t tests/test-lfs-serve-access.t tests/test-worker.t
diffstat 5 files changed, 10 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/error.py	Mon Nov 04 16:04:09 2019 +0100
+++ b/mercurial/error.py	Mon Nov 04 16:13:01 2019 +0100
@@ -111,6 +111,9 @@
 
     __bytes__ = _tobytes
 
+    def __str__(self):
+        return pycompat.sysstr(self.__bytes__())
+
 
 class HookLoadError(Abort):
     """raised when loading a hook fails, aborting an operation
--- a/tests/test-flagprocessor.t	Mon Nov 04 16:04:09 2019 +0100
+++ b/tests/test-flagprocessor.t	Mon Nov 04 16:13:01 2019 +0100
@@ -209,12 +209,12 @@
       insertflagprocessor(flag, processor, flagprocessors)
     File "*/mercurial/revlogutils/flagutil.py", line *, in insertflagprocessor (glob)
       raise error.Abort(msg)
-  mercurial.error.Abort: b"cannot register multiple processors on flag '0x8'." (py3 !)
+  mercurial.error.Abort: cannot register multiple processors on flag '0x8'. (py3 !)
   Abort: cannot register multiple processors on flag '0x8'. (no-py3 !)
   *** failed to set up extension duplicate: cannot register multiple processors on flag '0x8'.
   $ hg st 2>&1 | egrep 'cannot register multiple processors|flagprocessorext'
     File "*/tests/flagprocessorext.py", line *, in extsetup (glob)
-  mercurial.error.Abort: b"cannot register multiple processors on flag '0x8'." (py3 !)
+  mercurial.error.Abort: cannot register multiple processors on flag '0x8'. (py3 !)
   Abort: cannot register multiple processors on flag '0x8'. (no-py3 !)
   *** failed to set up extension duplicate: cannot register multiple processors on flag '0x8'.
     File "*/tests/flagprocessorext.py", line *, in b64decode (glob)
--- a/tests/test-hook.t	Mon Nov 04 16:04:09 2019 +0100
+++ b/tests/test-hook.t	Mon Nov 04 16:13:01 2019 +0100
@@ -988,7 +988,7 @@
   ModuleNotFoundError: No module named 'hgext_syntaxerror' (py36 !)
   Traceback (most recent call last): (py3 !)
   HookLoadError: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed (no-py3 !)
-  mercurial.error.HookLoadError: b'preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed' (py3 !)
+  mercurial.error.HookLoadError: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed (py3 !)
   abort: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed
 
   $ echo '[hooks]' > ../a/.hg/hgrc
@@ -1161,7 +1161,7 @@
   ModuleNotFoundError: No module named 'hgext_importfail' (py36 !)
   Traceback (most recent call last):
   HookLoadError: precommit.importfail hook is invalid: import of "importfail" failed (no-py3 !)
-  mercurial.error.HookLoadError: b'precommit.importfail hook is invalid: import of "importfail" failed' (py3 !)
+  mercurial.error.HookLoadError: precommit.importfail hook is invalid: import of "importfail" failed (py3 !)
   abort: precommit.importfail hook is invalid: import of "importfail" failed
 
 Issue1827: Hooks Update & Commit not completely post operation
--- a/tests/test-lfs-serve-access.t	Mon Nov 04 16:04:09 2019 +0100
+++ b/tests/test-lfs-serve-access.t	Mon Nov 04 16:13:01 2019 +0100
@@ -355,7 +355,7 @@
   $LOCALIP - - [$ERRDATE$] HG error:      super(badstore, self).download(oid, src) (glob)
   $LOCALIP - - [$ERRDATE$] HG error:      _(b'corrupt remote lfs object: %s') % oid (glob)
   $LOCALIP - - [$ERRDATE$] HG error:  LfsCorruptionError: corrupt remote lfs object: b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c (no-py3 !)
-  $LOCALIP - - [$ERRDATE$] HG error:  hgext.lfs.blobstore.LfsCorruptionError: b'corrupt remote lfs object: b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c' (py3 !)
+  $LOCALIP - - [$ERRDATE$] HG error:  hgext.lfs.blobstore.LfsCorruptionError: corrupt remote lfs object: b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c (py3 !)
   $LOCALIP - - [$ERRDATE$] HG error:   (glob)
   $LOCALIP - - [$ERRDATE$] Exception happened during processing request '/.hg/lfs/objects/276f73cfd75f9fb519810df5f5d96d6594ca2521abd86cbcd92122f7d51a1f3d': (glob)
   Traceback (most recent call last):
@@ -378,7 +378,7 @@
   $LOCALIP - - [$ERRDATE$] HG error:      blobstore._verify(oid, b'dummy content') (glob)
   $LOCALIP - - [$ERRDATE$] HG error:      hint=_(b'run hg verify'), (glob)
   $LOCALIP - - [$ERRDATE$] HG error:  LfsCorruptionError: detected corrupt lfs object: 276f73cfd75f9fb519810df5f5d96d6594ca2521abd86cbcd92122f7d51a1f3d (no-py3 !)
-  $LOCALIP - - [$ERRDATE$] HG error:  hgext.lfs.blobstore.LfsCorruptionError: b'detected corrupt lfs object: 276f73cfd75f9fb519810df5f5d96d6594ca2521abd86cbcd92122f7d51a1f3d' (py3 !)
+  $LOCALIP - - [$ERRDATE$] HG error:  hgext.lfs.blobstore.LfsCorruptionError: detected corrupt lfs object: 276f73cfd75f9fb519810df5f5d96d6594ca2521abd86cbcd92122f7d51a1f3d (py3 !)
   $LOCALIP - - [$ERRDATE$] HG error:   (glob)
 
 Basic Authorization headers are returned by the Batch API, and sent back with
--- a/tests/test-worker.t	Mon Nov 04 16:04:09 2019 +0100
+++ b/tests/test-worker.t	Mon Nov 04 16:13:01 2019 +0100
@@ -85,7 +85,7 @@
   $ hg --config "extensions.t=$abspath" --config 'worker.numcpus=8' \
   > test 100000.0 abort --traceback 2>&1 | egrep '(SystemExit|Abort)'
       raise error.Abort(b'known exception')
-  mercurial.error.Abort: b'known exception' (py3 !)
+  mercurial.error.Abort: known exception (py3 !)
   Abort: known exception (no-py3 !)
   SystemExit: 255