Patchwork D9178: errors: stop passing non-strings to Abort's constructor

login
register
mail settings
Submitter phabricator
Date Oct. 8, 2020, 11:11 p.m.
Message ID <differential-rev-PHID-DREV-hisjel3syzibnw2ddqz2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47413/
State Superseded
Headers show

Comments

phabricator - Oct. 8, 2020, 11:11 p.m.
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The next patch will change `Abort`'s constructor and `__bytes__`
  functions and they will start assuming that the first argument is the
  messages as `bytes`.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9178

AFFECTED FILES
  hgext/convert/cvsps.py
  mercurial/encoding.py
  mercurial/exchange.py
  tests/failfilemerge.py
  tests/test-bundle2-format.t
  tests/test-dirstate.t
  tests/test-fncache.t
  tests/test-histedit-edit.t
  tests/test-merge1.t
  tests/test-mq-qfold.t
  tests/test-mq-qnew.t
  tests/test-share-bookmarks.t
  tests/test-sparse-import.t

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/test-sparse-import.t b/tests/test-sparse-import.t
--- a/tests/test-sparse-import.t
+++ b/tests/test-sparse-import.t
@@ -153,7 +153,7 @@ 
   > from mercurial import error, sparse
   > def extsetup(ui):
   >     def abort_refresh(*args, **kwargs):
-  >         raise error.Abort('sparse._refresh called!')
+  >         raise error.Abort(b'sparse._refresh called!')
   >     sparse.refreshwdir = abort_refresh
   > EOF
   $ cat >> $HGRCPATH <<EOF
diff --git a/tests/test-share-bookmarks.t b/tests/test-share-bookmarks.t
--- a/tests/test-share-bookmarks.t
+++ b/tests/test-share-bookmarks.t
@@ -230,7 +230,7 @@ 
   > )
   > def _pullbookmarks(orig, pullop):
   >     orig(pullop)
-  >     raise error.HookAbort('forced failure by extension')
+  >     raise error.HookAbort(b'forced failure by extension')
   > def extsetup(ui):
   >     extensions.wrapfunction(exchange, '_pullbookmarks', _pullbookmarks)
   > EOF
diff --git a/tests/test-mq-qnew.t b/tests/test-mq-qnew.t
--- a/tests/test-mq-qnew.t
+++ b/tests/test-mq-qnew.t
@@ -256,7 +256,7 @@ 
   > def reposetup(ui, repo):
   >     class commitfailure(repo.__class__):
   >         def commit(self, *args, **kwargs):
-  >             raise error.Abort('emulating unexpected abort')
+  >             raise error.Abort(b'emulating unexpected abort')
   >     repo.__class__ = commitfailure
   > EOF
   $ cat >> .hg/hgrc <<EOF
diff --git a/tests/test-mq-qfold.t b/tests/test-mq-qfold.t
--- a/tests/test-mq-qfold.t
+++ b/tests/test-mq-qfold.t
@@ -153,7 +153,7 @@ 
   > def reposetup(ui, repo):
   >     class commitfailure(repo.__class__):
   >         def commit(self, *args, **kwargs):
-  >             raise error.Abort('emulating unexpected abort')
+  >             raise error.Abort(b'emulating unexpected abort')
   >     repo.__class__ = commitfailure
   > EOF
 
diff --git a/tests/test-merge1.t b/tests/test-merge1.t
--- a/tests/test-merge1.t
+++ b/tests/test-merge1.t
@@ -360,7 +360,7 @@ 
   > )
   > def applyupdates(orig, *args, **kwargs):
   >     orig(*args, **kwargs)
-  >     raise error.Abort('intentional aborting')
+  >     raise error.Abort(b'intentional aborting')
   > def extsetup(ui):
   >     extensions.wrapfunction(merge, "applyupdates", applyupdates)
   > EOF
diff --git a/tests/test-histedit-edit.t b/tests/test-histedit-edit.t
--- a/tests/test-histedit-edit.t
+++ b/tests/test-histedit-edit.t
@@ -311,7 +311,7 @@ 
   > def reposetup(ui, repo):
   >     class commitfailure(repo.__class__):
   >         def commit(self, *args, **kwargs):
-  >             raise error.Abort('emulating unexpected abort')
+  >             raise error.Abort(b'emulating unexpected abort')
   >     repo.__class__ = commitfailure
   > EOF
   $ cat >> .hg/hgrc <<EOF
diff --git a/tests/test-fncache.t b/tests/test-fncache.t
--- a/tests/test-fncache.t
+++ b/tests/test-fncache.t
@@ -238,7 +238,7 @@ 
   > def lockexception(orig, vfs, lockname, wait, releasefn, *args, **kwargs):
   >     def releasewrap():
   >         l.held = False # ensure __del__ is a noop
-  >         raise error.Abort("forced lock failure")
+  >         raise error.Abort(b"forced lock failure")
   >     l = orig(vfs, lockname, wait, releasewrap, *args, **kwargs)
   >     return l
   > 
diff --git a/tests/test-dirstate.t b/tests/test-dirstate.t
--- a/tests/test-dirstate.t
+++ b/tests/test-dirstate.t
@@ -74,7 +74,7 @@ 
   > )
   > 
   > def wraprecordupdates(*args):
-  >     raise error.Abort("simulated error while recording dirstateupdates")
+  >     raise error.Abort(b"simulated error while recording dirstateupdates")
   > 
   > def reposetup(ui, repo):
   >     extensions.wrapfunction(mergestatemod, 'recordupdates',
diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -22,6 +22,7 @@ 
   > from mercurial import changegroup
   > from mercurial import error
   > from mercurial import obsolete
+  > from mercurial import pycompat
   > from mercurial import registrar
   > from mercurial.utils import procutil
   > 
@@ -169,7 +170,7 @@ 
   >         for chunk in bundler.getchunks():
   >             file.write(chunk)
   >     except RuntimeError as exc:
-  >         raise error.Abort(exc)
+  >         raise error.Abort(pycompat.bytestr(exc))
   >     finally:
   >         file.flush()
   > 
diff --git a/tests/failfilemerge.py b/tests/failfilemerge.py
--- a/tests/failfilemerge.py
+++ b/tests/failfilemerge.py
@@ -12,7 +12,7 @@ 
 def failfilemerge(
     filemergefn, premerge, repo, wctx, mynode, orig, fcd, fco, fca, labels=None
 ):
-    raise error.Abort("^C")
+    raise error.Abort(b"^C")
     return filemergefn(premerge, repo, mynode, orig, fcd, fco, fca, labels)
 
 
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1720,7 +1720,7 @@ 
         repo = reporef()
         cm = _(b'accept incoming changes (yn)?$$ &Yes $$ &No')
         if repo.ui.promptchoice(cm):
-            raise error.Abort("user aborted")
+            raise error.Abort(b"user aborted")
 
     tr.addvalidator(b'900-pull-prompt', prompt)
 
diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -207,7 +207,9 @@ 
                 # can't round-trip
                 return u.encode(_sysstr(encoding), "replace")
     except LookupError as k:
-        raise error.Abort(k, hint=b"please check your locale settings")
+        raise error.Abort(
+            pycompat.bytestr(k), hint=b"please check your locale settings"
+        )
 
 
 def fromlocal(s):
diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py
+++ b/hgext/convert/cvsps.py
@@ -559,7 +559,7 @@ 
                     pass  # try next encoding
                 except LookupError as inst:  # unknown encoding, maybe
                     raise error.Abort(
-                        inst,
+                        pycompat.bytestr(inst),
                         hint=_(
                             b'check convert.cvsps.logencoding configuration'
                         ),