diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py index 62046b21b00abbf3fa8ea9a8e33fdaebdef2f237..d822d729ca9f1ab6f07caebd52ef57469aa56635 100644 --- a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py +++ b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py @@ -2,7 +2,7 @@ import logging -from tango import DeviceProxy, AttributeProxy, DevState +from tango import DeviceProxy, AttributeProxy, DevState, DevFailed import time import json, os @@ -250,11 +250,11 @@ class Archiver(): self.cm.AttributeStop(attribute_name) self.cm.AttributeRemove(attribute_name) logger.warning(f"Attribute {attribute_name} removed!") - except Exception as e: - if 'attribute not found' not in str(e).lower(): - raise Exception from e + except DevFailed as e: + if e.args[0].reason == 'Attribute not found': + logger.warning(f"Attribute {attribute_name} not found!") else: - logger.warning(f"Attribute {attribute_name} not found in archiving list!") + raise def remove_attributes_by_device(self,device_name:str,exclude:list=[]): """ @@ -297,11 +297,11 @@ class Archiver(): attribute_name = attribute_name_from_url(attribute_name) try: self.cm.AttributeStart(attribute_name) - except Exception as e: - if 'attribute not found' not in str(e).lower(): - raise Exception from e - else: + except DevFailed as e: + if e.args[0].reason == "Attribute not found": logger.warning(f"Attribute {attribute_name} not found!") + else: + raise def stop_archiving_attribute(self, attribute_name:str): """ @@ -311,11 +311,11 @@ class Archiver(): attribute_name = attribute_name_from_url(attribute_name) try: self.cm.AttributeStop(attribute_name) - except Exception as e: - if 'attribute not found' not in str(e).lower(): - raise Exception from e - else: + except DevFailed as e: + if e.args[0].reason == "Attribute not found": logger.warning(f"Attribute {attribute_name} not found!") + else: + raise def is_attribute_archived(self,attribute_name:str): """