Coverage for /Users/ajo/work/jumpstarter/jumpstarter/packages/jumpstarter/jumpstarter/common/exceptions.py: 65%
23 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:20 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-06 10:20 +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 raise SomeError("message") from original_exception
12 """
14 def __init__(self, message: str):
15 super().__init__(message)
16 self.message = message
18 def __str__(self):
19 if self.__cause__:
20 return f"{self.message} (Caused by: {self.__cause__})"
21 return f"{self.message}"
23 def print(self, message: str | None = None):
24 ANSI_RED = "\033[91m"
25 ANSI_CLEAR = "\033[0m"
26 print(f"{ANSI_RED}{self}{ANSI_CLEAR}", file=sys.stderr)
29class ConnectionError(JumpstarterException):
30 """Raised when a connection to a jumpstarter server fails."""
32 pass
35class ConfigurationError(JumpstarterException):
36 """Raised when a configuration error exists."""
38 pass
41class ArgumentError(JumpstarterException):
42 """Raised when a cli argument is not valid."""
44 pass
47class FileAccessError(JumpstarterException):
48 """Raised when a file access error occurs."""
50 pass
53class FileNotFoundError(JumpstarterException, FileNotFoundError):
54 """Raised when a file is not found."""
56 pass