Use ABCMeta for storm.exceptions?

Bug #1006711 reported by James Henstridge
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
Fix Released
Undecided
Colin Watson

Bug Description

In order to make error handling easier in storm.django, I filed https://code.djangoproject.com/ticket/15901 about getting Django to stop catching and re-raising errors from the database adapter so we could see them properly.

I had suggested a scheme similar to what we use with the Storm exceptions where we patch them into the inheritance hierarchy of the database adapter's existing exceptions. This didn't go over too well, and I had a second idea on how to achieve this using the abc module added in Python 2.6.

It lets us achieve a similar effect without patching __bases__. For instance:

    import abc

    class MyException(Exception):
        __metaclass__ = abc.ABCMeta

    MyException.register(ZeroDivisionError)

    try:
        1/0
    except MyException:
        print "Caught ZeroDivisionError with MyException"

Perhaps it would be cleaner if we did the same sort of thing in Storm?

It currently has some problems with Python 3.2 (see http://bugs.python.org/issue12029), but it seems that they consider this a bug to be fixed though.

Related branches

Revision history for this message
Colin Watson (cjwatson) wrote :

I took the ABCMeta approach in the branch I landed in 2016. Now I've merged a further refactoring to re-raise exceptions with diamond-inheritance exception types so that both "except <dbapi type>" and "except StormError" (etc.) keep working, while making things work in Python 3. This is somewhat like what Django ended up with after extensive discussion though with Storm-appropriate backward compatibility, and it's the best I've been able to come up with; some careful wrapper classes and context managers make the required boilerplate quite tolerable.

Changed in storm:
assignee: nobody → Colin Watson (cjwatson)
status: New → Fix Committed
Colin Watson (cjwatson)
Changed in storm:
milestone: none → 0.21
Colin Watson (cjwatson)
Changed in storm:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.