SiLab-Bonn / basil

A data acquisition framework in Python and Verilog.
BSD 3-Clause "New" or "Revised" License
40 stars 29 forks source link

Improve exception handling for dynamic method generation #202

Closed leloup314 closed 1 year ago

leloup314 commented 1 year ago

This PR adds more streamlined exception handling for the SCPI HL.

Currently, when the dynamically-generated method fails to create a SCPI command because of any exception, the bare exception is excepted and a ValueError is raised within the exception handling. Due to Pythons exception chaning, this produces a confusing traceback, not clearlyindictaing that no such attribute is available.

This PR changes this behavior by

  1. Catching and handling the possible exceptions occurring on SCPI command creation
  2. Checking for successful SCPI command creation and raising an AttributeError if no such SCPI method is available

This mirrors the expected behaviour of arbitrary_object.non_existing_method() generating an AttributeError

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.05 :tada:

Comparison is base (c29871f) 32.91% compared to head (428dc30) 32.96%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #202 +/- ## ========================================== + Coverage 32.91% 32.96% +0.05% ========================================== Files 84 84 Lines 5764 5769 +5 ========================================== + Hits 1897 1902 +5 Misses 3867 3867 ``` | [Impacted Files](https://codecov.io/gh/SiLab-Bonn/basil/pull/202?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=SiLab-Bonn) | Coverage Δ | | |---|---|---| | [basil/HL/scpi.py](https://codecov.io/gh/SiLab-Bonn/basil/pull/202?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=SiLab-Bonn#diff-YmFzaWwvSEwvc2NwaS5weQ==) | `87.14% <100.00%> (+0.98%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=SiLab-Bonn). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=SiLab-Bonn)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

leloup314 commented 1 year ago

@themperek any reason that SCPI hardware layer shout not raise an AttributeError when dynamically-generated method from __getattr__ tries to call SCPI command that does not exist? We are testing for a ValueError on any exception at the moment but that is probably not needed

themperek commented 1 year ago

@leloup314 I would be fine with this but this part is from @DavidLP

leloup314 commented 1 year ago

Probably will break peoples code... I guess it is not worth to change it for now.