From 5bb3d6c82ea6f826ba5b117882ff2aa797356100 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Thu, 22 Oct 2020 14:14:59 -0700 Subject: [PATCH] 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 --- hgext/absorb.py | 2 +- mercurial/commands.py | 6 +++--- mercurial/crecord.py | 2 +- mercurial/error.py | 7 +++++++ mercurial/exchange.py | 2 +- mercurial/patch.py | 2 +- mercurial/scmutil.py | 2 ++ mercurial/ui.py | 2 +- tests/test-commit-interactive.t | 6 +++--- tests/test-commit.t | 2 +- tests/test-editor-filename.t | 6 +++--- tests/test-rebase-collapse.t | 2 +- tests/test-rebase-transaction.t | 2 +- tests/test-resolve.t | 6 +++--- tests/test-revert-interactive.t | 2 +- tests/test-split.t | 2 +- 16 files changed, 31 insertions(+), 22 deletions(-) diff --git a/hgext/absorb.py b/hgext/absorb.py index 904410d458..f0d0d55e7a 100644 --- a/hgext/absorb.py +++ b/hgext/absorb.py @@ -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(): diff --git a/mercurial/commands.py b/mercurial/commands.py index b2535fb4be..c5604d21cf 100644 --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -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) diff --git a/mercurial/crecord.py b/mercurial/crecord.py index 52d94bdb2f..46c2d715b4 100644 --- a/mercurial/crecord.py +++ b/mercurial/crecord.py @@ -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"]: diff --git a/mercurial/error.py b/mercurial/error.py index f7873ccb78..3d3bffb8dd 100644 --- a/mercurial/error.py +++ b/mercurial/error.py @@ -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 diff --git a/mercurial/exchange.py b/mercurial/exchange.py index 4f02e9ee2f..9b9ece8b92 100644 --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -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 = _( diff --git a/mercurial/patch.py b/mercurial/patch.py index b2b86f4e37..c734602968 100644 --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -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() diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py index b5e8fb59ae..4344980d79 100644 --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -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) diff --git a/mercurial/ui.py b/mercurial/ui.py index 1b6cd5b1e6..f59053fe68 100644 --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -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', ) diff --git a/tests/test-commit-interactive.t b/tests/test-commit-interactive.t index 8efd578e17..1f36462ac1 100644 --- a/tests/test-commit-interactive.t +++ b/tests/test-commit-interactive.t @@ -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 diff --git a/tests/test-commit.t b/tests/test-commit.t index 4a1e7d8afe..f8a6ff88ac 100644 --- a/tests/test-commit.t +++ b/tests/test-commit.t @@ -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 diff --git a/tests/test-editor-filename.t b/tests/test-editor-filename.t index c22f316a94..eb7ce433ff 100644 --- a/tests/test-editor-filename.t +++ b/tests/test-editor-filename.t @@ -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] diff --git a/tests/test-rebase-collapse.t b/tests/test-rebase-collapse.t index 474f727383..f41556214e 100644 --- a/tests/test-rebase-collapse.t +++ b/tests/test-rebase-collapse.t @@ -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' | diff --git a/tests/test-rebase-transaction.t b/tests/test-rebase-transaction.t index 277f5142de..626ca6ee72 100644 --- a/tests/test-rebase-transaction.t +++ b/tests/test-rebase-transaction.t @@ -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 | diff --git a/tests/test-resolve.t b/tests/test-resolve.t index ac2b0f88ed..a53032acdd 100644 --- a/tests/test-resolve.t +++ b/tests/test-resolve.t @@ -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 diff --git a/tests/test-revert-interactive.t b/tests/test-revert-interactive.t index 37e7132540..ac2c343502 100644 --- a/tests/test-revert-interactive.t +++ b/tests/test-revert-interactive.t @@ -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 diff --git a/tests/test-split.t b/tests/test-split.t index d577b5c6cd..bb2b58a04c 100644 --- a/tests/test-split.t +++ b/tests/test-split.t @@ -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" -- GitLab