Ask Your Question

NeutronException not setting msg attribute for an Exception

asked 2014-03-14 01:28:08 -0500

updated 2014-03-17 23:38:24 -0500

I have custom messages in the plugin which I wish to bubble it to cli or dashboard in case of exceptions. I have written the following code in the plugin.

from neutron.common import exceptions

class RequestedStateInvalid(exceptions.NeutronException):
    def __init__(self, message = None):
        self.message = message
        super(RequestedStateInvalid, self).__init__()

But when I run this code, I get a message in the logs saying RequestedStateInvalid has no attribute called msg.

What I found is, NeutronException class in under common directory, I get type error when It tries to execute

super(NeutronException, self).__init__(self.message % kwargs)

and even when it goes into except Exception:

super(NeutronException, self).__init__(self.message)

it does no good as there is no self.msg set here.

Is this a bug or am I doing it wrong? Can someone explain what parameters to pass for kwargs?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-03-14 06:57:07 -0500

darragh-oreilly gravatar image

When I run that code it seems to work ok:

In [10]: try:
    raise RequestedStateInvalid('testing')
except Exception as e:
    print e

Anyway, the proper way to use NeutronException is described here. For example look at BridgeDoesNotExist

In [13]: raise exceptions.BridgeDoesNotExist(bridge='br123')
BridgeDoesNotExist                        Traceback (most recent call last)
/home/vagrant/<ipython-input-13-2e9acf6e3211> in <module>()
----> 1 raise exceptions.BridgeDoesNotExist(bridge='br123')

BridgeDoesNotExist: Bridge br123 does not exist.
edit flag offensive delete link more


Hi darragh, I tried exception handling using keyword arguments. I can see my custom messages coming on the CLI. When same exception is raised in horizon, I see it coming into the logs as "Recoverable error" but in GUI it comes as "Failed to delete class <uuid>". Any help with that?

prasoontelang gravatar imageprasoontelang ( 2014-03-17 23:09:22 -0500 )edit

I don't know about horizon.

darragh-oreilly gravatar imagedarragh-oreilly ( 2014-03-18 03:24:02 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-03-14 01:28:08 -0500

Seen: 110 times

Last updated: Mar 14 '14