Coverage for stricto/error.py: 100%

29 statements  

« 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 

3 

4PREFIX = "MODEL_" 

5 

6 

7class ErrorType(Enum): 

8 """ 

9 Specifics Errors for stricto. 

10 Use a ErrorType value (for future internationalisation) 

11 """ 

12 

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() 

27 

28 def __repr__(self): 

29 return PREFIX + self.name 

30 

31 

32class Error(TypeError): 

33 """ 

34 A Error returned by objects 

35 (use to internalize error messages) 

36 """ 

37 

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) 

42 

43 self.error_code = codeError 

44 self.message = message 

45 self.variable_name = variableName 

46 

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})"