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