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
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-26 17:28 +0200
1import sys
4class JumpstarterException(Exception):
5 """Base class for jumpstarter-specific errors.
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
11 .. code-block:: python
13 raise SomeError("message") from original_exception
14 """
16 def __init__(self, message: str):
17 super().__init__(message)
18 self.message = message
20 def __str__(self):
21 if self.__cause__:
22 return f"{self.message} (Caused by: {self.__cause__})"
23 return f"{self.message}"
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)
31class ConnectionError(JumpstarterException):
32 """Raised when a connection to a jumpstarter server fails."""
34 pass
37class ConfigurationError(JumpstarterException):
38 """Raised when a configuration error exists."""
40 pass
43class ArgumentError(JumpstarterException):
44 """Raised when a cli argument is not valid."""
46 pass
49class FileAccessError(JumpstarterException):
50 """Raised when a file access error occurs."""
52 pass
55class FileNotFoundError(JumpstarterException, FileNotFoundError):
56 """Raised when a file is not found."""
58 pass