<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<div>
<div>I would also argue in favor of MercurialException class to allow differentiation between our exceptions and all other ones. </div>
<div><br>
</div>
<div><br>
</div>
<div>-------- Original message --------</div>
<div>From: Augie Fackler <raf@durin42.com> </div>
<div>Date: 10/07/2016 20:36 (GMT+01:00) </div>
<div>To: Yuya Nishihara <yuya@tcha.org> </div>
<div>Cc: mercurial-devel@mercurial-scm.org </div>
<div>Subject: Re: [PATCH V2] error: make HintException a mix-in class not derived from BaseException (API)
</div>
<div><br>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">On Sat, Jul 09, 2016 at 03:20:36PM +0900, Yuya Nishihara wrote:<br>
> # HG changeset patch<br>
> # User Yuya Nishihara <yuya@tcha.org><br>
> # Date 1468042110 -32400<br>
> #      Sat Jul 09 14:28:30 2016 +0900<br>
> # Node ID bf279db10eb66c70322b062ef1818ddfb06e6daa<br>
> # Parent  b4d117cee636be8a566f56e84d4b351a736a1299<br>
> error: make HintException a mix-in class not derived from BaseException (API)<br>
><br>
> HintException is unrelated to the hierarchy of errors. It is an implementation<br>
> detail whether a class inherits from HintException or not, a sort of "private<br>
> inheritance" in C++.<br>
><br>
> New Hint isn't an exception class, which prevents catching error by its type:<br>
><br>
>     try:<br>
>         dosomething()<br>
>     except error.Hint:<br>
>         pass<br>
><br>
> Unfortunately, this passes on PyPy 5.3.1, but not on Python 2, and raises more<br>
> detailed TypeError on Python 3.<br>
><br>
> diff --git a/mercurial/error.py b/mercurial/error.py<br>
> --- a/mercurial/error.py<br>
> +++ b/mercurial/error.py<br>
> @@ -15,12 +15,17 @@ from __future__ import absolute_import<br>
><br>
>  # Do not import anything here, please<br>
><br>
> -class HintException(Exception):<br>
> +class Hint(object):<br>
> +    """Mix-in to provide a hint of an error<br>
> +<br>
> +    This should come first in the inheritance list to consume **kw and pass<br>
> +    only *args to the exception class.<br>
> +    """<br>
>      def __init__(self, *args, **kw):<br>
> -        Exception.__init__(self, *args)<br>
> +        super(Hint, self).__init__(*args)<br>
>          self.hint = kw.get('hint')<br>
<br>
should we do kw.pop('hint', None) and then forward **kw?<br>
<br>
><br>
> -class RevlogError(HintException):<br>
> +class RevlogError(Hint, Exception):<br>
>      pass<br>
><br>
>  class FilteredIndexError(IndexError):<br>
> @@ -50,10 +55,10 @@ class ManifestLookupError(LookupError):<br>
>  class CommandError(Exception):<br>
>      """Exception raised on errors in parsing the command line."""<br>
><br>
> -class InterventionRequired(HintException):<br>
> +class InterventionRequired(Hint, Exception):<br>
>      """Exception raised when a command requires human intervention."""<br>
><br>
> -class Abort(HintException):<br>
> +class Abort(Hint, Exception):<br>
>      """Raised if a command needs to print an error and exit."""<br>
><br>
>  class HookLoadError(Abort):<br>
> @@ -87,10 +92,10 @@ class ResponseExpected(Abort):<br>
>          from .i18n import _<br>
>          Abort.__init__(self, _('response expected'))<br>
><br>
> -class OutOfBandError(HintException):<br>
> +class OutOfBandError(Hint, Exception):<br>
>      """Exception raised when a remote repo reports failure"""<br>
><br>
> -class ParseError(HintException):<br>
> +class ParseError(Hint, Exception):<br>
>      """Raised when parsing config files and {rev,file}sets (msg[, pos])"""<br>
><br>
>  class UnknownIdentifier(ParseError):<br>
> @@ -102,7 +107,7 @@ class UnknownIdentifier(ParseError):<br>
>          self.function = function<br>
>          self.symbols = symbols<br>
><br>
> -class RepoError(HintException):<br>
> +class RepoError(Hint, Exception):<br>
>      pass<br>
><br>
>  class RepoLookupError(RepoError):<br>
> _______________________________________________<br>
> Mercurial-devel mailing list<br>
> Mercurial-devel@mercurial-scm.org<br>
> <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=gH42mpMAY9pB4Ok1rt9tBazPXiw6uw3RPUi4Z1cjk60&s=2_2nXaJTF4i9-d9uWpdkF_axE51iJpp5i-JYam6I8ps&e=">
https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=gH42mpMAY9pB4Ok1rt9tBazPXiw6uw3RPUi4Z1cjk60&s=2_2nXaJTF4i9-d9uWpdkF_axE51iJpp5i-JYam6I8ps&e=</a>
<br>
_______________________________________________<br>
Mercurial-devel mailing list<br>
Mercurial-devel@mercurial-scm.org<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=gH42mpMAY9pB4Ok1rt9tBazPXiw6uw3RPUi4Z1cjk60&s=2_2nXaJTF4i9-d9uWpdkF_axE51iJpp5i-JYam6I8ps&e=">https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Pp-gQYFgs4tKlSFPF5kfCw&m=gH42mpMAY9pB4Ok1rt9tBazPXiw6uw3RPUi4Z1cjk60&s=2_2nXaJTF4i9-d9uWpdkF_axE51iJpp5i-JYam6I8ps&e=</a>
<br>
</div>
</span></font>
</body>
</html>