Patchwork [07,of,10,py3] bundle2: obtain repr() of exception in a python3-safe way

login
register
mail settings
Submitter Augie Fackler
Date Aug. 1, 2017, 8:34 p.m.
Message ID <89d7a53b500a213396ab.1501619675@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/22615/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 1, 2017, 8:34 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1500909551 14400
#      Mon Jul 24 11:19:11 2017 -0400
# Node ID 89d7a53b500a213396ab3c8e043a31dc5538ccaf
# Parent  4c1f4e109bf90a8352a25a6b45a80fabcac6306b
bundle2: obtain repr() of exception in a python3-safe way

This was exposed by other problems in bundle generation, but I'm not
sure how to test it for now.
Yuya Nishihara - Aug. 2, 2017, 3:31 p.m.
On Tue, 01 Aug 2017 16:34:35 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1500909551 14400
> #      Mon Jul 24 11:19:11 2017 -0400
> # Node ID 89d7a53b500a213396ab3c8e043a31dc5538ccaf
> # Parent  4c1f4e109bf90a8352a25a6b45a80fabcac6306b
> bundle2: obtain repr() of exception in a python3-safe way
> 
> This was exposed by other problems in bundle generation, but I'm not
> sure how to test it for now.
> 
> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
> --- a/mercurial/bundle2.py
> +++ b/mercurial/bundle2.py
> @@ -1021,11 +1021,12 @@ class bundlepart(object):
>              ui.debug('bundle2-generatorexit\n')
>              raise
>          except BaseException as exc:
> +            bexc = pycompat.bytestr(exc)

This can raise UnicodeEncodeError because IOError on Python 3 may contain
non-ASCII unicode strings, for example. But still it is better, so queued.

I've queued 1, 5-10 for default, thanks.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1021,11 +1021,12 @@  class bundlepart(object):
             ui.debug('bundle2-generatorexit\n')
             raise
         except BaseException as exc:
+            bexc = pycompat.bytestr(exc)
             # backup exception data for later
             ui.debug('bundle2-input-stream-interrupt: encoding exception %s'
-                     % exc)
+                     % bexc)
             tb = sys.exc_info()[2]
-            msg = 'unexpected error: %s' % exc
+            msg = 'unexpected error: %s' % bexc
             interpart = bundlepart('error:abort', [('message', msg)],
                                    mandatory=False)
             interpart.id = 0