/
mi_exceptions.py
109 lines (87 loc) · 3.31 KB
/
mi_exceptions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
"""
@package ion.core.includes.mi_exceptions Exception classes for MI work
@file ion/services/mi/exceptions.py
@author Edward Hunter
@brief Common exceptions used in the MI work. Specific ones can be subclassed
in the driver code.
"""
#####
## For goodish reasons this file is maintained in both the marine-integration
## repository AND coi-services (HERE). It is required to keep these files
## synced.
##
## To maintain backwards capability exceptions in this file should not be
## changed or remove. We should only add.
#####
__author__ = 'Edward Hunter'
__license__ = 'Apache 2.0'
from ion.agents.instrument.common import BaseEnum
import traceback
class InstErrorCode(BaseEnum):
"""Error codes generated by instrument drivers and agents"""
TIMEOUT = ['ERROR_TIMEOUT','The message or operation timed out.']
REQUIRED_PARAMETER = ['ERROR_REQUIRED_PARAMETER','A required parameter was not specified.']
class InstrumentException(Exception):
"""Base class for an exception related to physical instruments or their
representation in ION.
"""
def __init__ (self, msg=None, error_code=None):
self.args = (error_code, msg)
self.error_code = error_code
self.msg = msg
class InstrumentConnectionException(InstrumentException):
"""Exception related to connection with a physical instrument"""
pass
class InstrumentProtocolException(InstrumentException):
"""Exception related to an instrument protocol problem
These are generally related to parsing or scripting of what is supposed
to happen when talking at the lowest layer protocol to a device.
@todo Add partial result property?
"""
pass
class InstrumentStateException(InstrumentException):
"""Exception related to an instrument state of any sort"""
pass
class InstrumentTimeoutException(InstrumentException):
"""Exception related to a command, request, or communication timing out"""
def __init__(self, error_code=InstErrorCode.TIMEOUT, msg=None):
InstrumentException.__init__(self, msg=msg, error_code=error_code)
class InstrumentDataException(InstrumentException):
"""Exception related to the data returned by an instrument or developed
along the path of handling that data"""
pass
class TestModeException(InstrumentException):
"""Attempt to run a test command while not in test mode"""
pass
class InstrumentCommandException(InstrumentException):
"""A problem with the command sent toward the instrument"""
pass
class InstrumentParameterException(InstrumentException):
"""A required parameter is not supplied"""
def __init__(self, msg=None, error_code=None):
if error_code == None:
error_code = InstErrorCode.REQUIRED_PARAMETER
if msg == None:
msg = ""
InstrumentException.__init__(self, error_code, msg)
class NotImplementedException(InstrumentException):
"""
A driver function is not implemented.
"""
pass
class ReadOnlyException(InstrumentException):
"""
A driver function is not implemented.
"""
pass
class SampleException(InstrumentException):
"""
An expected sample could not be extracted.
"""
pass
class SchedulerException(InstrumentException):
"""
An error occurred in the scheduler
"""
pass