[openstack-dev] [ceilometer] overuse of 'except Exception'

Doug Hellmann doug at doughellmann.com
Wed Jul 23 18:43:43 UTC 2014


On Jul 23, 2014, at 7:13 AM, Chris Dent <chdent at redhat.com> wrote:

> 
> I was having a bit of a browse through the ceilometer code and
> noticed there are a fair few instances (sixty-some) of
> `except Exception` scattered about.
> 
> While not as evil as a bare except, my Python elders always pointed
> out that doing `except Exception` is a bit like using a sledgehammer
> where something more akin to a gavel is what's wanted. The error
> condition is obliterated but there's no judgement on what happened
> and no apparent effort by the developer to effectively handle
> discrete cases.
> 
> A common idiom appears as:
> 
>    except Exception:
>        LOG.exception(_('something failed'))
>        return
>        # or continue
> 
> There's no information here about what failed or why.

LOG.exception() logs the full traceback, with the argument as a bit of context.

> 
> That's bad enough, but much worse, this will catch all sorts of
> exceptions, even ones that are completely unexpected and ought to
> cause a more drastic (and thus immediately informative) failure
> than 'something failed’.

In most cases, we chose to handle errors this way to keep the service running even in the face of “bad” data, since we are trying to collect an audit stream and we don’t want to miss good data if we encounter bad data.

> 
> So, my question: Is this something we who dig around in the ceilometer
> code ought to care about and make an effort to clean up? If so, I'm
> happy to get started.

If you would like to propose some changes for cases where more detailed exception handling is appropriate, we could discuss them on a case-by-case basis. I don’t think anyone used this exception handling lightly style and I wouldn’t want to change it without due consideration.

Doug

> 
> Thanks.
> 
> -- 
> Chris Dent tw:@anticdent freenode:cdent
> https://tank.peermore.com/tanks/cdent
> 
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev




More information about the OpenStack-dev mailing list