On Fri, May 01, 2020 at 09:23:20AM -0700, Christopher Barker wrote:
> I'm not sure how this could reasonably work, but maybe we could standardize
> that all Exceptions have an .errno attribute, and a standard mapping
> between the errorno and a message, or, ....
>
> Even if most Exceptions would have only a single error number, this would
> be a standardized way to add extra info to any Exception.
Okay, I've given this a bit more thought and I think that I have a way
to make this -- maybe -- practical without having to have a universal
global registry. There will still be a registry, but it will be per-
installation, and generated dynamically when exceptions are raised.
Whether it's useful, I don't know. (That's a polite way of saying I
don't think it is *wink* )
Whenever an exception is instantiated:
ValueError('too many chromions in the neutron flux')
`BaseException` looks for the combination of exception type and
error message in a per-site database. If they are not already in the DB,
it generates a new unique number for them. Once the error number is
generated or retrieved, it is added to the exception instance.
Exceptions like StopIteration will need to opt-out of this costly
process. That's easy enough: have the `BaseException.__init__` method
call a public `register` method to do the work. If you want to opt-out,
just set `register = None` in your class.
If one wanted to be a bit fancier, in a "Do What I Mean" kind of way, we
could use string similarity rather than equality, so that minor typos
in the error message won't be considered significant. The downside of
that is that
ValueError('too many chromions in the neutron flux')
ValueError('too few chromions in the neutron flux')
will probably count as being similar (edit distance of 1 word), which
you may not want.
Being site-specific, the error numbers won't necessarily correspond
between one site and the next. So you can't google for error numbers.
There would have to be some sort of tool for looking them up in the
database.
I'm not entirely sure what we would do with this error number once you
have it, but there it is. It was fun to think about.
If anyone wants to experiment with this, you can use a mixin class
in your exceptions without having to touch BaseException.
--
Steven
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/FUKGTWQ6WVY756TE5QX6N3OEDVHDD7MK/
Code of Conduct: http://python.org/psf/codeofconduct/