File: exceptions.py

package info (click to toggle)
python-can 4.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,372 kB
  • sloc: python: 25,840; makefile: 38; sh: 20
file content (28 lines) | stat: -rw-r--r-- 926 bytes parent folder | download | duplicates (2)
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)