Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Preserve cause of exception when getting/setting attribute in DeviceProxy #365

Merged
merged 5 commits into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions setup.py
Expand Up @@ -486,16 +486,21 @@ def setup_args():
setup_requires += ['pytest-runner']

tests_require = [
'pytest-xdist',
'gevent != 1.5a1',
'psutil',
]

if PYTHON2:
tests_require += [
'trollius', 'futures', 'pyparsing < 3', 'pytest < 5', 'zipp >= 0.5, < 2']
'futures',
'pyparsing < 3',
'pytest < 5',
'pytest-xdist < 2',
'trollius',
'zipp >= 0.5, < 2',
]
else:
tests_require += ['pytest']
tests_require += ['pytest', 'pytest-xdist']

package_data = {
'tango.databaseds': ['*.xmi', '*.sql', '*.sh', 'DataBaseds'],
Expand Down
45 changes: 28 additions & 17 deletions tango/device_proxy.py
Expand Up @@ -272,11 +272,12 @@ def __set_attribute_value(self, name, value):


def __DeviceProxy__getattr(self, name):
cause = None
# trait_names is a feature of IPython. Hopefully they will solve
# ticket http://ipython.scipy.org/ipython/ipython/ticket/229 someday
# and the ugly trait_names could be removed.
if name.startswith("_") or name == 'trait_names':
raise AttributeError(name)
six.raise_from(AttributeError(name), cause)

name_l = name.lower()

Expand All @@ -293,38 +294,42 @@ def __DeviceProxy__getattr(self, name):

try:
self.__refresh_cmd_cache()
except:
pass
except Exception as e:
if cause is None:
cause = e
Comment on lines +298 to +299
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would be multiple exceptions in this method if the device is off/unreachable, so keeping the first exception is a good approach 👍


cmd_info = self.__get_cmd_cache().get(name_l)
if cmd_info:
return __get_command_func(self, cmd_info, name)

try:
self.__refresh_attr_cache()
except:
pass
except Exception as e:
if cause is None:
cause = e

attr_info = self.__get_attr_cache().get(name_l)
if attr_info:
return __get_attribute_value(self, attr_info, name)

try:
self.__refresh_pipe_cache()
except Exception:
pass
except Exception as e:
if cause is None:
cause = e

if name_l in self.__get_pipe_cache():
return self.read_pipe(name)

raise AttributeError(name)
six.raise_from(AttributeError(name), cause)


def __DeviceProxy__setattr(self, name, value):
cause = None
name_l = name.lower()

if name_l in self.__get_cmd_cache():
raise TypeError('Cannot set the value of a command')
six.raise_from(TypeError('Cannot set the value of a command'), cause)

if name_l in self.__get_attr_cache():
return __set_attribute_value(self, name, value)
Expand All @@ -334,29 +339,35 @@ def __DeviceProxy__setattr(self, name, value):

try:
self.__refresh_cmd_cache()
except:
pass
except Exception as e:
if cause is None:
cause = e

if name_l in self.__get_cmd_cache():
raise TypeError('Cannot set the value of a command')
six.raise_from(TypeError('Cannot set the value of a command'), cause)

try:
self.__refresh_attr_cache()
except:
pass
except Exception as e:
if cause is None:
cause = e

if name_l in self.__get_attr_cache():
return __set_attribute_value(self, name, value)

try:
self.__refresh_pipe_cache()
except:
pass
except Exception as e:
if cause is None:
cause = e

if name_l in self.__get_pipe_cache():
return self.write_pipe(name, value)

return super(DeviceProxy, self).__setattr__(name, value)
try:
return super(DeviceProxy, self).__setattr__(name, value)
except Exception as e:
six.raise_from(e, cause)


def __DeviceProxy__dir(self):
Expand Down