microsoft / Qcodes

Modular data acquisition framework

Home Page:http://microsoft.github.io/Qcodes/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Acccessing a faulty property of an instrument throws obscure error.

qutech-lab opened this issue · comments

Acccessing a faulty property of an instrument raises obscure error.

If an instrument has a property which raises an exception when gotten, the resulting error trace obscures the source of the error.

Steps to reproduce

Take the following subclass of an instrument:

In [1]: import qcodes

In [2]: class Foo(qcodes.Instrument):
   ...:    @property
   ...:    def foo(self):
   ...:        return self.bar

Accessing the foo property raises the following error, which has no traceback or reference whatsoever to what actually causes the error, which is the missing bar attribute:

In [3]: foo = Foo('foo')
In [4]: foo.foo
Traceback (most recent call last):

  Cell In[4], line 1
    foo.foo

  File ~\Documents\Qcodes\src\qcodes\utils\attribute_helpers.py:69 in __getattr__
    raise AttributeError(

AttributeError: 'Foo' object and its delegates have no attribute 'foo'

This behavior makes these sorts of errors extremely cumbersome to debug if you're not aware of it. Instead, there should be a traceback to an AttributeError when getting self.bar in this example.

Branch: main @ 42c7483