errors: name arguments to Abort constructor
Differential Revision: https://phab.mercurial-scm.org/D9179
--- a/hgext/largefiles/overrides.py Thu Oct 08 15:35:44 2020 -0700
+++ b/hgext/largefiles/overrides.py Thu Oct 08 13:37:31 2020 -0700
@@ -734,7 +734,7 @@
try:
result = orig(ui, repo, pats, opts, rename)
except error.Abort as e:
- if pycompat.bytestr(e) != _(b'no files to copy'):
+ if e.message != _(b'no files to copy'):
raise e
else:
nonormalfiles = True
@@ -851,7 +851,7 @@
lfdirstate.add(destlfile)
lfdirstate.write()
except error.Abort as e:
- if pycompat.bytestr(e) != _(b'no files to copy'):
+ if e.message != _(b'no files to copy'):
raise e
else:
nolfiles = True
--- a/hgext/narrow/narrowwirepeer.py Thu Oct 08 15:35:44 2020 -0700
+++ b/hgext/narrow/narrowwirepeer.py Thu Oct 08 13:37:31 2020 -0700
@@ -13,7 +13,6 @@
extensions,
hg,
narrowspec,
- pycompat,
wireprototypes,
wireprotov1peer,
wireprotov1server,
@@ -125,7 +124,7 @@
)
except error.Abort as exc:
bundler = bundle2.bundle20(repo.ui)
- manargs = [(b'message', pycompat.bytestr(exc))]
+ manargs = [(b'message', exc.message)]
advargs = []
if exc.hint is not None:
advargs.append((b'hint', exc.hint))
--- a/mercurial/bundle2.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/bundle2.py Thu Oct 08 13:37:31 2020 -0700
@@ -2089,7 +2089,7 @@
except error.Abort as e:
raise error.Abort(
_(b'bundle at %s is corrupted:\n%s')
- % (util.hidepassword(raw_url), bytes(e))
+ % (util.hidepassword(raw_url), e.message)
)
assert not inpart.read()
--- a/mercurial/chgserver.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/chgserver.py Thu Oct 08 13:37:31 2020 -0700
@@ -502,7 +502,7 @@
self.cresult.write(b'exit 255')
return
except error.Abort as inst:
- self.ui.error(_(b"abort: %s\n") % inst)
+ self.ui.error(_(b"abort: %s\n") % inst.message)
if inst.hint:
self.ui.error(_(b"(%s)\n") % inst.hint)
self.ui.flush()
--- a/mercurial/commandserver.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/commandserver.py Thu Oct 08 13:37:31 2020 -0700
@@ -500,7 +500,7 @@
# handle exceptions that may be raised by command server. most of
# known exceptions are caught by dispatch.
except error.Abort as inst:
- ui.error(_(b'abort: %s\n') % inst)
+ ui.error(_(b'abort: %s\n') % inst.message)
except IOError as inst:
if inst.errno != errno.EPIPE:
raise
--- a/mercurial/crecord.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/crecord.py Thu Oct 08 13:37:31 2020 -0700
@@ -1808,7 +1808,7 @@
try:
patch = self.ui.edit(patch.getvalue(), b"", action=b"diff")
except error.Abort as exc:
- self.errorstr = stringutil.forcebytestr(exc)
+ self.errorstr = exc.message
return None
finally:
self.stdscr.clear()
--- a/mercurial/debugcommands.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/debugcommands.py Thu Oct 08 13:37:31 2020 -0700
@@ -1770,7 +1770,7 @@
try:
username = ui.username()
except error.Abort as e:
- err = stringutil.forcebytestr(e)
+ err = e.message
problems += 1
fm.condwrite(
--- a/mercurial/dispatch.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/dispatch.py Thu Oct 08 13:37:31 2020 -0700
@@ -288,7 +288,7 @@
if req.fmsg:
req.ui.fmsg = req.fmsg
except error.Abort as inst:
- ferr.write(_(b"abort: %s\n") % inst)
+ ferr.write(_(b"abort: %s\n") % inst.message)
if inst.hint:
ferr.write(_(b"(%s)\n") % inst.hint)
return -1
--- a/mercurial/error.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/error.py Thu Oct 08 13:37:31 2020 -0700
@@ -155,7 +155,15 @@
class Abort(Hint, Exception):
"""Raised if a command needs to print an error and exit."""
- __bytes__ = _tobytes
+ def __init__(self, message, hint=None):
+ self.message = message
+ self.hint = hint
+ # Pass the message into the Exception constructor to help extensions
+ # that look for exc.args[0].
+ Exception.__init__(self, message)
+
+ def __bytes__(self):
+ return self.message
if pycompat.ispy3:
--- a/mercurial/hgweb/hgweb_mod.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/hgweb/hgweb_mod.py Thu Oct 08 13:37:31 2020 -0700
@@ -493,7 +493,7 @@
except error.Abort as e:
res.status = b'403 Forbidden'
res.headers[b'Content-Type'] = ctype
- return rctx.sendtemplate(b'error', error=pycompat.bytestr(e))
+ return rctx.sendtemplate(b'error', error=e.message)
except ErrorResponse as e:
for k, v in e.headers:
res.headers[k] = v
--- a/mercurial/match.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/match.py Thu Oct 08 13:37:31 2020 -0700
@@ -355,7 +355,10 @@
except error.Abort as inst:
raise error.Abort(
b'%s: %s'
- % (pat, inst[0]) # pytype: disable=unsupported-operands
+ % (
+ pat,
+ inst.message,
+ ) # pytype: disable=unsupported-operands
)
except IOError as inst:
if warn:
--- a/mercurial/scmutil.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/scmutil.py Thu Oct 08 13:37:31 2020 -0700
@@ -216,7 +216,7 @@
except error.WdirUnsupported:
ui.error(_(b"abort: working directory revision cannot be specified\n"))
except error.Abort as inst:
- ui.error(_(b"abort: %s\n") % inst)
+ ui.error(_(b"abort: %s\n") % inst.message)
if inst.hint:
ui.error(_(b"(%s)\n") % inst.hint)
except ImportError as inst:
--- a/mercurial/subrepo.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/subrepo.py Thu Oct 08 13:37:31 2020 -0700
@@ -39,7 +39,6 @@
dateutil,
hashutil,
procutil,
- stringutil,
)
hg = None
@@ -84,9 +83,7 @@
except error.Abort as ex:
subrepo = subrelpath(self)
errormsg = (
- stringutil.forcebytestr(ex)
- + b' '
- + _(b'(in subrepository "%s")') % subrepo
+ ex.message + b' ' + _(b'(in subrepository "%s")') % subrepo
)
# avoid handling this exception by raising a SubrepoAbort exception
raise SubrepoAbort(
--- a/mercurial/wireprotov1server.py Thu Oct 08 15:35:44 2020 -0700
+++ b/mercurial/wireprotov1server.py Thu Oct 08 13:37:31 2020 -0700
@@ -497,11 +497,11 @@
# cleanly forward Abort error to the client
if not exchange.bundle2requested(opts.get(b'bundlecaps')):
if proto.name == b'http-v1':
- return wireprototypes.ooberror(pycompat.bytestr(exc) + b'\n')
+ return wireprototypes.ooberror(exc.message + b'\n')
raise # cannot do better for bundle1 + ssh
# bundle2 request expect a bundle2 reply
bundler = bundle2.bundle20(repo.ui)
- manargs = [(b'message', pycompat.bytestr(exc))]
+ manargs = [(b'message', exc.message)]
advargs = []
if exc.hint is not None:
advargs.append((b'hint', exc.hint))
@@ -684,7 +684,7 @@
# We did not change it to minimise code change.
# This need to be moved to something proper.
# Feel free to do it.
- procutil.stderr.write(b"abort: %s\n" % exc)
+ procutil.stderr.write(b"abort: %s\n" % exc.message)
if exc.hint is not None:
procutil.stderr.write(b"(%s)\n" % exc.hint)
procutil.stderr.flush()
@@ -733,7 +733,7 @@
if exc.params:
errpart.addparam(b'params', b'\0'.join(exc.params))
except error.Abort as exc:
- manargs = [(b'message', stringutil.forcebytestr(exc))]
+ manargs = [(b'message', exc.message)]
advargs = []
if exc.hint is not None:
advargs.append((b'hint', exc.hint))
--- a/tests/bruterebase.py Thu Oct 08 15:35:44 2020 -0700
+++ b/tests/bruterebase.py Thu Oct 08 13:37:31 2020 -0700
@@ -52,7 +52,7 @@
try:
rebase.rebase(ui, repo, dest=dest, rev=[spec])
except error.Abort as ex:
- summary = b'ABORT: %s' % ex
+ summary = b'ABORT: %s' % ex.message
except Exception as ex:
summary = b'CRASH: %s' % ex
else:
--- a/tests/test-url.py Thu Oct 08 15:35:44 2020 -0700
+++ b/tests/test-url.py Thu Oct 08 13:37:31 2020 -0700
@@ -392,7 +392,7 @@
>>> try:
... u = url(b'file://mercurial-scm.org/foo')
... except error.Abort as e:
- ... forcebytestr(e)
+ ... e.message
'file:// URLs can only refer to localhost'
Empty URL: