Source code for src.core.errors
"""Custom-defined exceptions.
The following custom-defined exceptions are defined in this module.
InstrumentInUseError
Raised when a user attempts to delete an instrument which is still
used by an action in the sequence.
InvalidInputError
Raised when a user enters an input value which is not of the right
type.
"""
import logging
log = logging.getLogger('transport')
[docs]class InstrumentInUseError(Exception):
"""Error for when an attempt is made to delete a still-bound instrument.
Parameters
----------
actions : list of Action
A list of the actions which require the instrument the user is
trying to delete.
"""
def __init__(self, actions):
"""Create a new InstrumentInUseError."""
super(InstrumentInUseError, self).__init__('The instrument is in use.')
self.actions = actions
super(InstrumentInUseError, self).__init__('The instrument is in use.')
[docs]class GeneralExperimentError(Exception):
"""An exception generated in response to miscellaneous problems.
Parameters
----------
items : list of tuple of str
A list of tuples. Each tuple contains information about one error in
the form of two strings. The first is the severity and may be either
'warning', which will allow the experiment to proceed if the user
commands it, or 'error', which will not allow the experiment to
proceed. The second is a message about the error.
Attributes
----------
msg : str
A basic string: 'Errors have been found.'
items : list of tuple of str
The same as `items` from the Parameters section.
errorCount : int
The number of elements of `items` which are 'error's rather than
mere 'warning's.
"""
def __init__(self, items):
"""Create a new GeneralExperimentError"""
self.msg = 'Errors have been found.'
self.items = items
self.errorCount = 0
for item in items:
if item[0] == 'error':
self.errorCount += 1
self.args = (self.msg, self.items, self.errorCount)
super(GeneralExperimentError, self).__init__(self.msg)
[docs]class Null(object):
"""Fake VISA driver.
This class is here so that the program will run even on a computer without
VISA drivers installed.
"""
def __init__(self, *args, **kwargs):
"""Do nothing."""
log.error(('No VISA drivers: Cannot create object. Args=[%s]. '
'Kwargs=[%s]'), args, kwargs)
def __call__(self, *args, **kwargs):
"""Cannot call method, so do nothing."""
log.error('No VISA drivers: Cannot call method.')
return self
def __getattribute__(self, *args, **kwargs):
"""Cannot get attribute, so do nothing."""
try:
if args[0] == '__bases__':
return []
except IndexError:
pass
log.error('No VISA drivers: Cannot get attribute. %s', args)
return self
def __setattr__(self, name, value):
"""Cannot set attribute, so do nothing."""
log.error('No VISA drivers: Cannot set attribute.')
def __delattr__(self, name):
"""Cannot delete attribute, so do nothing."""
log.error('No VISA drivers: Cannot delete attribute.')