mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-25 20:34:26 -08:00
128 lines
3.8 KiB
Python
128 lines
3.8 KiB
Python
class FastAnimeError(Exception):
|
|
"""
|
|
Base exception for all custom errors raised by the FastAnime library and application.
|
|
|
|
Catching this exception will catch any error originating from within this project,
|
|
distinguishing it from built-in Python errors or third-party library errors.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
# ==============================================================================
|
|
# Configuration and Initialization Errors
|
|
# ==============================================================================
|
|
|
|
|
|
class ConfigError(FastAnimeError):
|
|
"""
|
|
Represents an error found in the user's configuration file (config.ini).
|
|
|
|
This is typically raised by the ConfigLoader when validation fails.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class DependencyNotFoundError(FastAnimeError):
|
|
"""
|
|
A required external command-line tool (e.g., ffmpeg, fzf) was not found.
|
|
|
|
This indicates a problem with the user's environment setup.
|
|
"""
|
|
|
|
def __init__(self, dependency_name: str, hint: str | None = None):
|
|
self.dependency_name = dependency_name
|
|
message = (
|
|
f"Required dependency '{dependency_name}' not found in your system's PATH."
|
|
)
|
|
if hint:
|
|
message += f"\nHint: {hint}"
|
|
super().__init__(message)
|
|
|
|
|
|
# ==============================================================================
|
|
# Provider and Network Errors
|
|
# ==============================================================================
|
|
|
|
|
|
class ProviderError(FastAnimeError):
|
|
"""
|
|
Base class for all errors related to an anime provider.
|
|
|
|
This allows for catching any provider-related issue while still allowing
|
|
for more specific error handling of its subclasses.
|
|
"""
|
|
|
|
def __init__(self, provider_name: str, message: str):
|
|
self.provider_name = provider_name
|
|
super().__init__(f"[{provider_name.capitalize()}] {message}")
|
|
|
|
|
|
class ProviderAPIError(ProviderError):
|
|
"""
|
|
An error occurred while communicating with the provider's API.
|
|
|
|
This typically corresponds to network issues, timeouts, or HTTP error
|
|
status codes like 4xx (client error) or 5xx (server error).
|
|
"""
|
|
|
|
def __init__(
|
|
self, provider_name: str, http_status: int | None = None, details: str = ""
|
|
):
|
|
self.http_status = http_status
|
|
message = "An API communication error occurred."
|
|
if http_status:
|
|
message += f" (Status: {http_status})"
|
|
if details:
|
|
message += f" Details: {details}"
|
|
super().__init__(provider_name, message)
|
|
|
|
|
|
class ProviderParsingError(ProviderError):
|
|
"""
|
|
Failed to parse or find expected data in the provider's response.
|
|
|
|
This often indicates that the source website's HTML structure or API
|
|
response schema has changed, and the provider's parser needs to be updated.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
# ==============================================================================
|
|
# Application Logic and Workflow Errors
|
|
# ==============================================================================
|
|
|
|
|
|
class DownloaderError(FastAnimeError):
|
|
"""
|
|
An error occurred during the file download or post-processing phase.
|
|
|
|
This can be raised by the YTDLPService for issues like failed downloads
|
|
or ffmpeg merging errors.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class InvalidEpisodeRangeError(FastAnimeError, ValueError):
|
|
"""
|
|
The user-provided episode range string is malformed or invalid.
|
|
|
|
Inherits from ValueError for semantic compatibility but allows for specific
|
|
catching as a FastAnimeError.
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class NoStreamsFoundError(ProviderError):
|
|
"""
|
|
A provider was successfully queried, but no streamable links were returned.
|
|
"""
|
|
|
|
def __init__(self, provider_name: str, anime_title: str, episode: str):
|
|
message = f"No streams were found for '{anime_title}' episode {episode}."
|
|
super().__init__(provider_name, message)
|