Coverage for stricto/error.py: 100%
29 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-08 18:02 +0100
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-08 18:02 +0100
1"""Module providing Error management"""
2from enum import Enum, auto
4PREFIX = "MODEL_"
7class ErrorType(Enum):
8 """
9 Specifics Errors for stricto.
10 Use a ErrorType value (for future internationalisation)
11 """
13 WRONGTYPE = auto()
14 NOTALIST = auto()
15 NOTADICT = auto()
16 NOTONEOF = auto()
17 NULL = auto()
18 NOTATYPE = auto()
19 UNKNOWNCONTENT = auto()
20 NOTCALLABLE = auto()
21 CONSTRAINT = auto()
22 UNION = auto()
23 REGEXP = auto()
24 LENGTH = auto()
25 DUP = auto()
26 READONLY = auto()
28 def __repr__(self):
29 return PREFIX + self.name
32class Error(TypeError):
33 """
34 A Error returned by objects
35 (use to internalize error messages)
36 """
38 def __init__(self, codeError: str, message, variableName: str = None):
39 """ """
40 # Call the base class conDictor with the parameters it needs
41 TypeError.__init__(self, message)
43 self.error_code = codeError
44 self.message = message
45 self.variable_name = variableName
47 def __str__(self):
48 if self.variable_name:
49 return f"{self.variable_name}: {self.message} ({self.error_code})"
50 return f"{self.message} ({self.error_code})"