Commit 5bb3d6c8 authored by Martin von Zweigbergk's avatar Martin von Zweigbergk

errors: introduce CanceledError and use it in a few places

This very similar to earlier patches (e.g. for `InputError`) and part
of https://www.mercurial-scm.org/wiki/ErrorCategoriesPlan.

Differential Revision: https://phab.mercurial-scm.org/D9339
parent 568c05d8f3d2
......@@ -1076,7 +1076,7 @@ def absorb(ui, repo, stack=None, targetctx=None, pats=None, opts=None):
b"apply changes (y/N)? $$ &Yes $$ &No", default=1
)
):
raise error.Abort(_(b'absorb cancelled\n'))
raise error.CanceledError(_(b'absorb cancelled\n'))
state.apply()
if state.commit():
......
......@@ -5830,7 +5830,7 @@ def resolve(ui, repo, *pats, **opts):
if ui.promptchoice(
_(b're-merge all unresolved files (yn)?$$ &Yes $$ &No')
):
raise error.Abort(_(b'user quit'))
raise error.CanceledError(_(b'user quit'))
if mark and not pats:
if ui.promptchoice(
_(
......@@ -5838,7 +5838,7 @@ def resolve(ui, repo, *pats, **opts):
b'$$ &Yes $$ &No'
)
):
raise error.Abort(_(b'user quit'))
raise error.CanceledError(_(b'user quit'))
if unmark and not pats:
if ui.promptchoice(
_(
......@@ -5846,7 +5846,7 @@ def resolve(ui, repo, *pats, **opts):
b'$$ &Yes $$ &No'
)
):
raise error.Abort(_(b'user quit'))
raise error.CanceledError(_(b'user quit'))
uipathfn = scmutil.getuipathfn(repo)
......
......@@ -1894,7 +1894,7 @@ are you sure you want to review/edit and confirm the selected changes [yn]?
elif keypressed in ["H", "KEY_SLEFT"]:
self.leftarrowshiftevent()
elif keypressed in ["q"]:
raise error.Abort(_(b'user quit'))
raise error.CanceledError(_(b'user quit'))
elif keypressed in ['a']:
self.flipselections()
elif keypressed in ["c"]:
......
......@@ -195,6 +195,13 @@ class StateError(Abort):
"""
class CanceledError(Abort):
"""Indicates that the user canceled the operation.
Examples: Close commit editor with error status, quit chistedit.
"""
class HookLoadError(Abort):
"""raised when loading a hook fails, aborting an operation
......
......@@ -193,7 +193,7 @@ def _checkpublish(pushop):
_(b'push and publish %i changesets (yn)?$$ &Yes $$ &No')
% len(published)
):
raise error.Abort(_(b'user quit'))
raise error.CanceledError(_(b'user quit'))
elif behavior == b'abort':
msg = _(b'push would publish %i changesets') % len(published)
hint = _(
......
......@@ -1272,7 +1272,7 @@ the hunk is left unchanged.
elif r == 6: # all
ret = skipall = True
elif r == 7: # quit
raise error.Abort(_(b'user quit'))
raise error.CanceledError(_(b'user quit'))
return ret, skipfile, skipall, newpatches
seen = set()
......
......@@ -261,6 +261,8 @@ def callcatch(ui, func):
detailed_exit_code = 20
elif isinstance(inst, error.ConfigError):
detailed_exit_code = 30
elif isinstance(inst, error.CanceledError):
detailed_exit_code = 250
ui.error(_(b"abort: %s\n") % inst.message)
if inst.hint:
ui.error(_(b"(%s)\n") % inst.hint)
......
......@@ -1852,7 +1852,7 @@ class ui(object):
self.system(
b"%s \"%s\"" % (editor, name),
environ=environ,
onerr=error.Abort,
onerr=error.CanceledError,
errprefix=_(b"edit failed"),
blockedtag=b'editor',
)
......
......@@ -885,7 +885,7 @@ Help, quit
(enter ? for help) [Ynesfdaq?] q
abort: user quit
[255]
[250]
Patterns
......@@ -1014,7 +1014,7 @@ f, quit
(enter ? for help) [Ynesfdaq?] q
abort: user quit
[255]
[250]
s, all
......@@ -1419,7 +1419,7 @@ Trying to edit patch for whole file
(enter ? for help) [Ynesfdaq?] q
abort: user quit
[255]
[250]
$ hg revert editedfile
Removing changes from patch
......
......@@ -155,7 +155,7 @@ Failed commit with --addremove should not update dirstate
$ HGEDITOR=false hg ci --addremove
adding newfile
abort: edit failed: false exited with status 1
[255]
[250]
$ hg status
? newfile
......
......@@ -17,7 +17,7 @@ Verify that the path for a commit editor has the expected suffix.
$ hg commit
*.commit.hg.txt (glob)
abort: edit failed: sh exited with status 1
[255]
[250]
Verify that the path for a histedit editor has the expected suffix.
......@@ -30,7 +30,7 @@ Verify that the path for a histedit editor has the expected suffix.
$ hg histedit
*.histedit.hg.txt (glob)
abort: edit failed: sh exited with status 1
[255]
[250]
Verify that when performing an action that has the side-effect of creating an
editor for a diff, the file ends in .diff.
......@@ -61,4 +61,4 @@ editor for a diff, the file ends in .diff.
(enter ? for help) [Ynesfdaq?] q
abort: user quit
[255]
[250]
......@@ -760,7 +760,7 @@ Test aborted editor on final message
already rebased 1:f899f3910ce7 B "B" as 82b8abf9c185
rebasing 3:63668d570d21 C tip "C"
abort: edit failed: false exited with status 1
[255]
[250]
$ hg tglog
o 3: 63668d570d21 'C'
|
......
......@@ -171,7 +171,7 @@ rebase can then be continued
transaction abort!
rollback completed
abort: edit failed: false exited with status 1
[255]
[250]
$ hg tglog
o 5: D
|
......
......@@ -495,7 +495,7 @@ Test when config option is set:
> EOF
re-merge all unresolved files (yn)? n
abort: user quit
[255]
[250]
$ hg resolve --all << EOF
> y
......@@ -523,7 +523,7 @@ Test that commands.resolve.confirm respect --mark option (only when no patterns
> EOF
mark all unresolved files as resolved (yn)? n
abort: user quit
[255]
[250]
$ hg resolve -m << EOF
> y
......@@ -551,7 +551,7 @@ Test that commands.resolve.confirm respect --unmark option (only when no pattern
> EOF
mark all resolved files as unresolved (yn)? n
abort: user quit
[255]
[250]
$ hg resolve -m << EOF
> y
......
......@@ -153,7 +153,7 @@ Test that --interactive lift the need for --all
(enter ? for help) [Ynesfdaq?] q
abort: user quit
[255]
[250]
$ ls folder1/
g
......
......@@ -159,7 +159,7 @@ was always recording three commits, one for each diff hunk, in reverse order
transaction abort!
rollback completed
abort: edit failed: false exited with status 1
[255]
[250]
$ hg status
$ HGEDITOR="\"$PYTHON\" $TESTTMP/editor.py"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment