Skip to content
Snippets Groups Projects
Commit de418833 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-548: Annotate which attribute is giving errors

parent e15625f7
No related branches found
No related tags found
1 merge request!201L2SS-548: Annotate which attribute is giving errors
......@@ -145,13 +145,38 @@ class attribute_wrapper(attribute):
return value
def _decorate_read_function(self, read_attr_func):
""" Wrap an attribute read function to annotate its exceptions with our
comms_annotation to be able to identify which attribute triggered the error. """
def wrapper():
try:
return read_attr_func()
except Exception as e:
raise Exception(f"Failed to read attribute {self.comms_annotation}") from e
return wrapper
def _decorate_write_function(self, write_attr_func):
""" Wrap an attribute write function to annotate its exceptions with our
comms_annotation to be able to identify which attribute triggered the error. """
def wrapper(value):
try:
write_attr_func(value)
except Exception as e:
raise Exception(f"Failed to write attribute {self.comms_annotation}") from e
return wrapper
def set_comm_client(self, client):
"""
takes a communications client as input arguments This client should be of a class containing a "get_mapping" function
and return a read and write function that the wrapper will use to get/set data.
"""
try:
self.read_function, self.write_function = client.setup_attribute(self.comms_annotation, self)
read_attr_func, write_attr_func = client.setup_attribute(self.comms_annotation, self)
self.read_function = self._decorate_read_function(read_attr_func)
self.write_function = self._decorate_write_function(write_attr_func)
except Exception as e:
raise Exception(f"Exception while setting {client.__class__.__name__} attribute with annotation: '{self.comms_annotation}'") from e
......@@ -160,7 +185,10 @@ class attribute_wrapper(attribute):
Asynchronous version of set_comm_client.
"""
try:
self.read_function, self.write_function = await client.setup_attribute(self.comms_annotation, self)
read_attr_func, write_attr_func = await client.setup_attribute(self.comms_annotation, self)
self.read_function = self._decorate_read_function(read_attr_func)
self.write_function = self._decorate_write_function(write_attr_func)
except Exception as e:
raise Exception(f"Exception while setting {client.__class__.__name__} attribute with annotation: '{self.comms_annotation}'") from e
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment