From patchwork Wed May 19 05:48:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: D10738: errors: create superclass for Abort exception From: phabricator X-Patchwork-Id: 49057 Message-Id: To: Phabricator Cc: mercurial-devel@mercurial-scm.org Date: Wed, 19 May 2021 05:48:36 +0000 martinvonz created this revision. Herald added a reviewer: hg-reviewers. Herald added a subscriber: mercurial-patches. REVISION SUMMARY I'd like to let extensions subclass `StorageError` to define a custom exit code. However, `StorageError` does not extend `Abort` (which is where the exit code currently lives), and it seems that it's not supposed to either (`StorageError` seems to be for lower-level errors and `Abort` is for command-level errors). This patch therefore extracts all the code from `Abort` into a new `Error` class, which I'll soon make `StorageError` also extend. REPOSITORY rHG Mercurial BRANCH default REVISION DETAIL https://phab.mercurial-scm.org/D10738 AFFECTED FILES mercurial/error.py CHANGE DETAILS To: martinvonz, #hg-reviewers Cc: mercurial-patches, mercurial-devel diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -51,8 +51,8 @@ super(Hint, self).__init__(*args, **kw) -class Abort(Hint, Exception): - """Raised if a command needs to print an error and exit.""" +class Error(Hint, Exception): + """Base class for Mercurial errors.""" def __init__( self, message, hint=None, coarse_exit_code=None, detailed_exit_code=None @@ -87,6 +87,10 @@ return message +class Abort(Error): + """Raised if a command needs to print an error and exit.""" + + class StorageError(Hint, Exception): """Raised when an error occurs in a storage layer.