From 2b68c88c880327ac224efb029935b71067290b32 Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Fri, 17 Dec 2021 15:15:50 +0100 Subject: [PATCH] L2SS-544: Parse exceptions more directly --- .../tangostationcontrol/toolkit/archiver.py | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tangostationcontrol/tangostationcontrol/toolkit/archiver.py b/tangostationcontrol/tangostationcontrol/toolkit/archiver.py index 62046b21b..d822d729c 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): """ -- GitLab