[Zope3-dev] Re: [Zope-dev] Re: tal:on-error is a bare except...
Tres Seaver
tseaver at zope.com
Sun Aug 22 21:35:26 EDT 2004
Jim Fulton wrote:
> Tres Seaver wrote:
>> I don't believe the bare except is *ever* good form in
>> production-quality code. *No* application-level code has enough zen
>> to swallow some kinds of exceptions, which is why the Java folks have
>> a separate RuntimeError hierarchy.
>
> This isn't application level code.
I guess I don't know what you mean by I "application level": the code
path occurs because some application developer put '<div tal:on-error>'
into a template to "prettify" the error messages. That hardly feels
like "infrastructure" coding to me.
Perhaps where we agree is in calling a bug the fact that the
implementation of the on-error handler (like 'hasattr'!) uses a bare except.
>> The fact that newer ZODB's *appear* to prevent later commits does not
>> exculpate the use of the bare except in 'tal:on-error' (emphasis added
>> to indicate a non-trivial amount of suspicion against the code paths
>> in question; we have claimed to have solved that problem before).
>
>
> Right, we have to do something different here. Adding a dependency on
> ZODB isn't an option. There needs to be some framework for deciding
> which exceptions to catch and which not to. It's hard though, because
> we do want to catch conflict errors. We just don't want to catch them
> anywhere but the publisher.
>
> I'm open to suggestions that don't involve sprinling references to
> ConflictError all over the place.
We could introduce a new base exception, not dependent on ZODB, and then
sprinkle references to *that* everywhere:
# zExceptions.py -- I don't recall where this belongs in Zope3
class FrameworkError:
""" Base for exceptions not intended to be caught by default.
"""
# ZODB3/POSException.py -- likewise
class POSError(FrameworkError):
"""Persistent object system error.
"""
Ripping out bare 'except:' is *not* easy (which is why I think it is the
single biggest wart in Python).
Tres.
--
===============================================================
Tres Seaver tseaver at zope.com
Zope Corporation "Zope Dealers" http://www.zope.com
More information about the Zope3-dev
mailing list