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
|
"""Exception/error declarations for the vector interface."""
from can import CanError, CanInitializationError, CanOperationError
class VectorError(CanError):
def __init__(self, error_code, error_string, function):
super().__init__(
message=f"{function} failed ({error_string})", error_code=error_code
)
# keep reference to args for pickling
self._args = error_code, error_string, function
def __reduce__(self):
return type(self), self._args, {}
class VectorInitializationError(VectorError, CanInitializationError):
@staticmethod
def from_generic(error: VectorError) -> "VectorInitializationError":
return VectorInitializationError(*error._args)
class VectorOperationError(VectorError, CanOperationError):
@staticmethod
def from_generic(error: VectorError) -> "VectorOperationError":
return VectorOperationError(*error._args)
|