diff --git a/secop/errors.py b/secop/errors.py index 3cbbda3..6d652a1 100644 --- a/secop/errors.py +++ b/secop/errors.py @@ -138,6 +138,12 @@ def secop_error(exception): return InternalError(repr(exception)) +def fmt_error(exception): + if isinstance(exception, SECoPError): + return str(exception) + return repr(exception) + + EXCEPTIONS = dict( NoSuchModule=NoSuchModuleError, NoSuchParameter=NoSuchParameterError, diff --git a/secop/protocol/dispatcher.py b/secop/protocol/dispatcher.py index 3c6e903..9f6c022 100644 --- a/secop/protocol/dispatcher.py +++ b/secop/protocol/dispatcher.py @@ -43,7 +43,7 @@ from collections import OrderedDict from time import time as currenttime from secop.errors import BadValueError, NoSuchCommandError, NoSuchModuleError, \ - NoSuchParameterError, ProtocolError, ReadOnlyError, SECoPServerError + NoSuchParameterError, ProtocolError, ReadOnlyError, SECoPServerError, fmt_error from secop.params import Parameter from secop.protocol.messages import COMMANDREPLY, DESCRIPTIONREPLY, \ DISABLEEVENTSREPLY, ENABLEEVENTSREPLY, ERRORPREFIX, EVENTREPLY, \ @@ -53,8 +53,8 @@ from secop.protocol.messages import COMMANDREPLY, DESCRIPTIONREPLY, \ def make_update(modulename, pobj): if pobj.readerror: return (ERRORPREFIX + EVENTREPLY, '%s:%s' % (modulename, pobj.export), - # error-report ! - [pobj.readerror.name, repr(pobj.readerror), dict(t=pobj.timestamp)]) + # error-report ! + [pobj.readerror.name, fmt_error(pobj.readerror), dict(t=pobj.timestamp)]) return (EVENTREPLY, '%s:%s' % (modulename, pobj.export), [pobj.export_value(), dict(t=pobj.timestamp)])