Patchwork [2,of,2,STABLE] py3: add a __str__ method to Abort

login
register
mail settings
Submitter Denis Laxalde
Date Nov. 4, 2019, 3:14 p.m.
Message ID <f3fa4fc93f68baf007c9.1572880453@marimba>
Download mbox | patch
Permalink /patch/42710/
State Accepted
Headers show

Comments

Denis Laxalde - Nov. 4, 2019, 3:14 p.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1572880381 -3600
#      Mon Nov 04 16:13:01 2019 +0100
# Branch stable
# Node ID f3fa4fc93f68baf007c9e24ded876f649a028728
# Parent  cb58293505fa65d1b7f2a7d0e3fc3b3320122ac6
py3: add a __str__ method to Abort

This improves the rendering of some exceptions by avoiding raw
bytestrings, especially when using --traceback option.
Augie Fackler - Nov. 4, 2019, 4:07 p.m.
queued for stable, thanks

> On Nov 4, 2019, at 10:14, Denis Laxalde <denis@laxalde.org> wrote:
> 
> # HG changeset patch
> # User Denis Laxalde <denis@laxalde.org>
> # Date 1572880381 -3600
> #      Mon Nov 04 16:13:01 2019 +0100
> # Branch stable
> # Node ID f3fa4fc93f68baf007c9e24ded876f649a028728
> # Parent  cb58293505fa65d1b7f2a7d0e3fc3b3320122ac6
> py3: add a __str__ method to Abort
> 
> This improves the rendering of some exceptions by avoiding raw
> bytestrings, especially when using --traceback option.
> 
> diff --git a/mercurial/error.py b/mercurial/error.py
> --- a/mercurial/error.py
> +++ b/mercurial/error.py
> @@ -111,6 +111,9 @@ class Abort(Hint, Exception):
> 
>     __bytes__ = _tobytes
> 
> +    def __str__(self):
> +        return pycompat.sysstr(self.__bytes__())
> +
> 
> class HookLoadError(Abort):
>     """raised when loading a hook fails, aborting an operation
> diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
> --- a/tests/test-flagprocessor.t
> +++ b/tests/test-flagprocessor.t
> @@ -209,12 +209,12 @@ Ensure the data got to the server OK
>       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)
> diff --git a/tests/test-hook.t b/tests/test-hook.t
> --- a/tests/test-hook.t
> +++ b/tests/test-hook.t
> @@ -988,7 +988,7 @@ test python hooks
>   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 @@ make sure --traceback works on hook impo
>   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
> diff --git a/tests/test-lfs-serve-access.t b/tests/test-lfs-serve-access.t
> --- a/tests/test-lfs-serve-access.t
> +++ b/tests/test-lfs-serve-access.t
> @@ -355,7 +355,7 @@ Test a checksum failure during the proce
>   $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 @@ Test a checksum failure during the proce
>   $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
> diff --git a/tests/test-worker.t b/tests/test-worker.t
> --- a/tests/test-worker.t
> +++ b/tests/test-worker.t
> @@ -85,7 +85,7 @@ Known exception should be caught, but pr
>   $ 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
> 
> 
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/error.py b/mercurial/error.py
--- a/mercurial/error.py
+++ b/mercurial/error.py
@@ -111,6 +111,9 @@  class Abort(Hint, Exception):
 
     __bytes__ = _tobytes
 
+    def __str__(self):
+        return pycompat.sysstr(self.__bytes__())
+
 
 class HookLoadError(Abort):
     """raised when loading a hook fails, aborting an operation
diff --git a/tests/test-flagprocessor.t b/tests/test-flagprocessor.t
--- a/tests/test-flagprocessor.t
+++ b/tests/test-flagprocessor.t
@@ -209,12 +209,12 @@  Ensure the data got to the server OK
       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)
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -988,7 +988,7 @@  test python hooks
   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 @@  make sure --traceback works on hook impo
   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
diff --git a/tests/test-lfs-serve-access.t b/tests/test-lfs-serve-access.t
--- a/tests/test-lfs-serve-access.t
+++ b/tests/test-lfs-serve-access.t
@@ -355,7 +355,7 @@  Test a checksum failure during the proce
   $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 @@  Test a checksum failure during the proce
   $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
diff --git a/tests/test-worker.t b/tests/test-worker.t
--- a/tests/test-worker.t
+++ b/tests/test-worker.t
@@ -85,7 +85,7 @@  Known exception should be caught, but pr
   $ 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