pymeasure: check_errors usage inconsistent

Our Instrument.check_errors() implementation returns a list of received errors (as its docstring says).

Interestingly though, where we use them, e.g. in control’s fget, https://github.com/pymeasure/pymeasure/blob/ebf6df97e229c0e916192a495ade65053b234ac3/pymeasure/instruments/instrument.py#L361, we simply discard those return values without doing anything!

I think where we use it we should do something with the errors, most probably log them.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (24 by maintainers)

Most upvoted comments

What do you think about a slight duplication of logging?

We could retain the current behaviour of default check_errors, i.e.

  • log errors
  • return list of errors

check_get/set_errors document that they (if overridden) shall

  • log received errors
  • return a list of encountered errors
  • Optionally may raise an Exception if a critical error is encountered

Property fget/fset, if they receive an error during checking, log that error + useful context (command). So we might get

…error: KeithleyXYZ: 235, baz is borked (from check_errors) …error: Error received after writing “POW 1”: “235, baz is borked” (from within property fget/fset)

This way, we ensure that

  • we get logging on error by default, even if the error does not happen within a property
  • we get additional useful context if this happens in a property
  • error checking always returns something that can be easily processed in code
  • we document that an instrument may raise an Exception if deemed appropriate

Thoughts?