Better exception handling with handle_exception

Bug #1298221 reported by Ladislav Smola
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tuskar
Opinion
Medium
Unassigned

Bug Description

Wee need to get rid of all 'except Exception' blocks

e.g. https://github.com/openstack/tuskar/blob/master/tuskar/api/controllers/v1/overcloud.py#L155

The best way to do this is to come up with handle_exception abstraction, that will have list of all heat known exceptions. In this case it will return exception message to user, otherwise it will re-raise the unknown exception.

Ladislav Smola (lsmola)
Changed in tuskar:
importance: Undecided → High
status: New → Triaged
Dougal Matthews (d0ugal)
Changed in tuskar:
assignee: nobody → Dougal Matthews (d0ugal)
Revision history for this message
Dougal Matthews (d0ugal) wrote :

I spent a bit of time trying to come up with something nicer and I spoke with Jay about it briefly. I don't think we should change this.

The code shows the intention clearly and generates good errors by raising different exceptions. The main negative I can see is that it is quite verbose. We can't easily change the exception handling because the errors from heat are not specific enough to figure out what we should then re-raise it as.

So, I've bumped this down to medium priority as I'm not convinced it should be changed. It certainly isn't a high priority issue, the error handling works well in its current state.

Changed in tuskar:
assignee: Dougal Matthews (d0ugal) → nobody
importance: High → Medium
Revision history for this message
Ladislav Smola (lsmola) wrote :

So I might wasn't clear in the explanation.

I wanted to implement something like this
https://github.com/openstack/horizon/blob/master/horizon/exceptions.py#L215
that would be used like this
https://github.com/openstack/horizon/blob/028332da4acb1ef6b9b9a1026affcf97e5501a84/openstack_dashboard/dashboards/admin/roles/forms.py#L35
(with showing exception message like it is doing now e.g.)

Now the handle would know that allowed exceptions are e.g. HeatSomethinException and HeatSomethingElseException.
So if it will throw e.g. AttributeError, it will re-raise the exception instead of printing message to user.

So the main reason of this bug is that using except Exception is really bad, cause it catches more than we want. But defining every-time except X,Y,Z.., would be extremely tedious.
The Horizon handle way seems like a reasonable way to go, so we have code, that does the right thing and is not crazily verbose.

Revision history for this message
Dougal Matthews (d0ugal) wrote :

hmm, that was roughly how I understood it but I don't see how the linked example is better?

The example you linked to, https://github.com/openstack/horizon/blob/028332da4acb1ef6b9b9a1026affcf97e5501a84/openstack_dashboard/dashboards/admin/roles/forms.py#L35, still catches (almost) all exceptions?

Jay Dobies (jdob)
Changed in tuskar:
status: Triaged → Opinion
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.