89 lines
3.6 KiB
Python
89 lines
3.6 KiB
Python
# LauncherTool/core/exceptions.py
|
|
"""
|
|
Custom exceptions for the core logic of the application.
|
|
"""
|
|
|
|
class ConfigError(Exception):
|
|
"""Base class for configuration related errors."""
|
|
pass
|
|
|
|
class ConfigFileNotFoundError(ConfigError):
|
|
"""Raised when the configuration file is not found."""
|
|
def __init__(self, filepath):
|
|
self.filepath = filepath
|
|
super().__init__(f"Configuration file not found: {filepath}")
|
|
|
|
class ConfigDecodeError(ConfigError):
|
|
"""Raised when the configuration file cannot be decoded (e.g., invalid JSON)."""
|
|
def __init__(self, filepath, original_exception=None):
|
|
self.filepath = filepath
|
|
self.original_exception = original_exception
|
|
message = f"Error decoding configuration file: {filepath}."
|
|
if original_exception:
|
|
message += f" Original error: {original_exception}"
|
|
super().__init__(message)
|
|
|
|
class ConfigLoadError(ConfigError):
|
|
"""Raised for general errors during configuration loading."""
|
|
def __init__(self, filepath, original_exception=None):
|
|
self.filepath = filepath
|
|
self.original_exception = original_exception
|
|
message = f"Failed to load configuration from: {filepath}."
|
|
if original_exception:
|
|
message += f" Original error: {original_exception}"
|
|
super().__init__(message)
|
|
|
|
class ConfigSaveError(ConfigError):
|
|
"""Raised for errors during configuration saving."""
|
|
def __init__(self, filepath, original_exception=None):
|
|
self.filepath = filepath
|
|
self.original_exception = original_exception
|
|
message = f"Failed to save configuration to: {filepath}."
|
|
if original_exception:
|
|
message += f" Original error: {original_exception}"
|
|
super().__init__(message)
|
|
|
|
class DuplicateNameError(ConfigError):
|
|
"""Raised when attempting to add an item with a name that already exists."""
|
|
def __init__(self, item_type, name):
|
|
self.item_type = item_type
|
|
self.name = name
|
|
super().__init__(f"A {item_type} with the name '{name}' already exists.")
|
|
|
|
class NameNotFoundError(ConfigError):
|
|
"""Raised when an item with the specified name is not found."""
|
|
def __init__(self, item_type, name):
|
|
self.item_type = item_type
|
|
self.name = name
|
|
super().__init__(f"{item_type.capitalize()} with name '{name}' not found.")
|
|
|
|
class ApplicationNotFoundError(NameNotFoundError):
|
|
"""Raised when a specific application is not found in the configuration."""
|
|
def __init__(self, app_name):
|
|
super().__init__("application", app_name)
|
|
|
|
class SequenceNotFoundError(NameNotFoundError):
|
|
"""Raised when a specific sequence is not found in the configuration."""
|
|
def __init__(self, seq_name):
|
|
super().__init__("sequence", seq_name)
|
|
|
|
class ExecutionError(Exception):
|
|
"""Base class for errors during command execution."""
|
|
pass
|
|
|
|
class CommandExecutionError(ExecutionError):
|
|
"""Raised when a command fails to execute."""
|
|
def __init__(self, command, original_exception=None):
|
|
self.command = command
|
|
self.original_exception = original_exception
|
|
message = f"Error executing command: {' '.join(command)}."
|
|
if original_exception:
|
|
message += f" Original error: {original_exception}"
|
|
super().__init__(message)
|
|
|
|
class ApplicationPathNotFoundError(ExecutionError, FileNotFoundError):
|
|
"""Raised when an application's executable path is not found."""
|
|
def __init__(self, app_name, app_path):
|
|
self.app_name = app_name
|
|
self.app_path = app_path
|
|
super().__init__(f"Executable for application '{app_name}' not found at path: {app_path}") |