client: detect original frappy error class
The text part of the error report contains the original error class - convert it to the frappy error class, if possible. This makes the error messages on the client nicer, as the error class would be duplicated in the error message on the client side. Change-Id: If2e0c3eb15ac2dd1b80a851ff42e4076557a325d
This commit is contained in:
parent
db3b190c26
commit
59cc981566
@ -22,6 +22,9 @@
|
||||
# *****************************************************************************
|
||||
"""Define (internal) SECoP Errors"""
|
||||
|
||||
import re
|
||||
from ast import literal_eval
|
||||
|
||||
|
||||
class SECoPError(RuntimeError):
|
||||
silent = False # silent = True indicates that the error is already logged
|
||||
@ -121,8 +124,27 @@ class HardwareError(SECoPError):
|
||||
name = 'HardwareError'
|
||||
|
||||
|
||||
FRAPPY_ERROR = re.compile(r'(.*)\(.*\)$')
|
||||
|
||||
|
||||
def make_secop_error(name, text):
|
||||
errcls = EXCEPTIONS.get(name, InternalError)
|
||||
"""create an instance of SECoPError from an error report
|
||||
|
||||
:param name: the error class from the SECoP error report
|
||||
:param text: the second item of a SECoP error report
|
||||
:return: the built instance of SECoPError
|
||||
"""
|
||||
try:
|
||||
# try to interprete the error text as a repr(<instance of SECoPError>)
|
||||
# as it would be created by a Frappy server
|
||||
cls, textarg = FRAPPY_ERROR.match(text).groups()
|
||||
errcls = locals()[cls]
|
||||
if errcls.name == name:
|
||||
# convert repr(<string>) to <string>
|
||||
text = literal_eval(textarg)
|
||||
except Exception:
|
||||
# probably not a Frappy server, or running a different version
|
||||
errcls = EXCEPTIONS.get(name, InternalError)
|
||||
return errcls(text)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user