Merge "client: detect original frappy error class"

This commit is contained in:
zolliker 2023-01-19 12:29:37 +01:00 committed by Gerrit Code Review
commit 85295a7d72

View File

@ -22,6 +22,9 @@
# ***************************************************************************** # *****************************************************************************
"""Define (internal) SECoP Errors""" """Define (internal) SECoP Errors"""
import re
from ast import literal_eval
class SECoPError(RuntimeError): class SECoPError(RuntimeError):
silent = False # silent = True indicates that the error is already logged silent = False # silent = True indicates that the error is already logged
@ -121,7 +124,26 @@ class HardwareError(SECoPError):
name = 'HardwareError' name = 'HardwareError'
FRAPPY_ERROR = re.compile(r'(.*)\(.*\)$')
def make_secop_error(name, text): def make_secop_error(name, text):
"""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) errcls = EXCEPTIONS.get(name, InternalError)
return errcls(text) return errcls(text)