diff --git a/confluent_server/confluent/exceptions.py b/confluent_server/confluent/exceptions.py index e1c19c4d..c359e40d 100644 --- a/confluent_server/confluent/exceptions.py +++ b/confluent_server/confluent/exceptions.py @@ -19,6 +19,19 @@ import base64 import json import msgpack +def exc_text(theexc): + """Render an exception for a user, even when it carries no message. + + An error with no text at all tells the user nothing, so fall back to the + description a confluent exception carries by class, and then to the name of + the exception. + """ + text = str(theexc) + if text and text != 'None': + return text + return getattr(theexc, '_apierrorstr', None) or type(theexc).__name__ + + def deserialize_exc(msg): excd = msgpack.unpackb(msg, raw=False) if excd[0] == 'Exception': @@ -35,8 +48,7 @@ class ConfluentException(Exception): _apierrorstr = 'Unexpected Error' def get_error_body(self): - errstr = ' - '.join((self._apierrorstr, str(self))) - return json.dumps({'error': errstr }) + return json.dumps({'error': self.apierrorstr}) def serialize(self): return msgpack.packb([self.__class__.__name__, [str(self)]], diff --git a/confluent_server/confluent/plugins/hardwaremanagement/enclosure.py b/confluent_server/confluent/plugins/hardwaremanagement/enclosure.py index 8714a753..31f0c69f 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/enclosure.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/enclosure.py @@ -29,11 +29,11 @@ async def reseat_bays(encmgr, bays, configmanager, rspq): inputdata={'reseat': encbay}): await rspq.put(rsp) except pygexc.UnsupportedFunctionality as uf: - await rspq.put(msg.ConfluentNodeError(node, str(uf))) + await rspq.put(msg.ConfluentNodeError(node, exc.exc_text(uf))) except exc.TargetEndpointUnreachable as uf: - await rspq.put(msg.ConfluentNodeError(node, str(uf))) + await rspq.put(msg.ConfluentNodeError(node, exc.exc_text(uf))) except Exception as e: - await rspq.put(msg.ConfluentNodeError(node, str(e))) + await rspq.put(msg.ConfluentNodeError(node, exc.exc_text(e))) finally: await rspq.put(None) diff --git a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py index c2898693..f59fbb3c 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/ipmi.py @@ -15,6 +15,7 @@ import asyncio import confluent.exceptions as exc +from confluent.exceptions import exc_text import confluent.firmwaremanager as firmwaremanager import confluent.interface.console as conapi import confluent.messages as msg @@ -284,18 +285,6 @@ def _donothing(data): pass -def exc_text(theexc): - """Render an exception for a user, even when it carries no message. - - An error with no text at all tells the user nothing, so name the exception - when that is all we have. - """ - text = str(theexc) - if not text or text == 'None': - return type(theexc).__name__ - return text - - class IpmiConsole(conapi.Console): configattributes = frozenset(_configattributes) bmctonodemapping = {} diff --git a/confluent_server/confluent/plugins/hardwaremanagement/redfish.py b/confluent_server/confluent/plugins/hardwaremanagement/redfish.py index 1dc81b00..6c276d30 100644 --- a/confluent_server/confluent/plugins/hardwaremanagement/redfish.py +++ b/confluent_server/confluent/plugins/hardwaremanagement/redfish.py @@ -17,6 +17,7 @@ import json import asyncio import confluent.vinzmanager as vinzmanager import confluent.exceptions as exc +from confluent.exceptions import exc_text import confluent.firmwaremanager as firmwaremanager import confluent.messages as msg import confluent.util as util @@ -272,18 +273,6 @@ def _donothing(data): pass -def exc_text(theexc): - """Render an exception for a user, even when it carries no message. - - An error with no text at all tells the user nothing, so name the exception - when that is all we have. - """ - text = str(theexc) - if not text or text == 'None': - return type(theexc).__name__ - return text - - async def perform_requests(operator, nodes, element, cfg, inputdata, realop): cryptit = cfg.decrypt cfg.decrypt = True