Coverage for /Users/ajo/work/jumpstarter/jumpstarter/packages/jumpstarter/jumpstarter/common/exceptions.py: 74%

23 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-26 17:28 +0200

1import sys 

2 

3 

4class JumpstarterException(Exception): 

5 """Base class for jumpstarter-specific errors. 

6 

7 This class should not be raised directly, but should be used as a base 

8 class for all jumpstarter-specific errors. 

9 It handles the __cause__ attribute so the jumpstarter errors could be raised as 

10 

11 .. code-block:: python 

12 

13 raise SomeError("message") from original_exception 

14 """ 

15 

16 def __init__(self, message: str): 

17 super().__init__(message) 

18 self.message = message 

19 

20 def __str__(self): 

21 if self.__cause__: 

22 return f"{self.message} (Caused by: {self.__cause__})" 

23 return f"{self.message}" 

24 

25 def print(self, message: str | None = None): 

26 ANSI_RED = "\033[91m" 

27 ANSI_CLEAR = "\033[0m" 

28 print(f"{ANSI_RED}{self}{ANSI_CLEAR}", file=sys.stderr) 

29 

30 

31class ConnectionError(JumpstarterException): 

32 """Raised when a connection to a jumpstarter server fails.""" 

33 

34 pass 

35 

36 

37class ConfigurationError(JumpstarterException): 

38 """Raised when a configuration error exists.""" 

39 

40 pass 

41 

42 

43class ArgumentError(JumpstarterException): 

44 """Raised when a cli argument is not valid.""" 

45 

46 pass 

47 

48 

49class FileAccessError(JumpstarterException): 

50 """Raised when a file access error occurs.""" 

51 

52 pass 

53 

54 

55class FileNotFoundError(JumpstarterException, FileNotFoundError): 

56 """Raised when a file is not found.""" 

57 

58 pass