Zum Inhalt

Exceptions-Modul

exceptions

Custom exceptions for Weeb CLI.

This module defines the exception hierarchy for error handling throughout the application. All exceptions inherit from WeebCLIError base class.

Exception Hierarchy

WeebCLIError (base) ├── ProviderError: Anime provider-related errors ├── DownloadError: Download operation failures ├── NetworkError: Network connectivity issues ├── AuthenticationError: Tracker authentication failures ├── DatabaseError: Database operation errors ├── ValidationError: Input validation failures └── DependencyError: External dependency issues

Example

Raising exceptions::

from weeb_cli.exceptions import ProviderError, DownloadError

raise ProviderError("Failed to fetch anime", code="PROVIDER_001")
raise DownloadError("Insufficient disk space", code="DISK_FULL")

Catching exceptions::

try:
    provider.search("anime")
except ProviderError as e:
    print(f"Provider error: {e.message} ({e.code})")
except WeebCLIError as e:
    print(f"General error: {e}")

WeebCLIError

Bases: Exception

Base exception for all Weeb CLI errors.

Provides structured error handling with optional error codes for better error tracking and debugging.

Attributes:

Name Type Description
message str

Human-readable error message.

code str

Optional error code for categorization.

Source code in weeb_cli/exceptions.py
class WeebCLIError(Exception):
    """Base exception for all Weeb CLI errors.

    Provides structured error handling with optional error codes for
    better error tracking and debugging.

    Attributes:
        message (str): Human-readable error message.
        code (str): Optional error code for categorization.
    """

    def __init__(self, message: str = "", code: str = "") -> None:
        """Initialize exception with message and optional code.

        Args:
            message: Descriptive error message.
            code: Optional error code (e.g., 'PROVIDER_001').
        """
        self.message = message
        self.code = code
        super().__init__(f"{code}: {message}" if code else message)

__init__

__init__(message: str = '', code: str = '') -> None

Initialize exception with message and optional code.

Parameters:

Name Type Description Default
message str

Descriptive error message.

''
code str

Optional error code (e.g., 'PROVIDER_001').

''
Source code in weeb_cli/exceptions.py
def __init__(self, message: str = "", code: str = "") -> None:
    """Initialize exception with message and optional code.

    Args:
        message: Descriptive error message.
        code: Optional error code (e.g., 'PROVIDER_001').
    """
    self.message = message
    self.code = code
    super().__init__(f"{code}: {message}" if code else message)

ProviderError

Bases: WeebCLIError

Exception raised for anime provider-related errors.

Used when providers fail to search, fetch details, or extract streams.

Source code in weeb_cli/exceptions.py
class ProviderError(WeebCLIError):
    """Exception raised for anime provider-related errors.

    Used when providers fail to search, fetch details, or extract streams.
    """
    pass

DownloadError

Bases: WeebCLIError

Exception raised for download operation failures.

Used when downloads fail due to network issues, disk space, or invalid stream URLs.

Source code in weeb_cli/exceptions.py
class DownloadError(WeebCLIError):
    """Exception raised for download operation failures.

    Used when downloads fail due to network issues, disk space, or
    invalid stream URLs.
    """
    pass

NetworkError

Bases: WeebCLIError

Exception raised for network connectivity issues.

Used when HTTP requests fail or network is unavailable.

Source code in weeb_cli/exceptions.py
class NetworkError(WeebCLIError):
    """Exception raised for network connectivity issues.

    Used when HTTP requests fail or network is unavailable.
    """
    pass

AuthenticationError

Bases: WeebCLIError

Exception raised for tracker authentication failures.

Used when OAuth flows fail or credentials are invalid.

Source code in weeb_cli/exceptions.py
class AuthenticationError(WeebCLIError):
    """Exception raised for tracker authentication failures.

    Used when OAuth flows fail or credentials are invalid.
    """
    pass

DatabaseError

Bases: WeebCLIError

Exception raised for database operation errors.

Used when SQLite operations fail or database is corrupted.

Source code in weeb_cli/exceptions.py
class DatabaseError(WeebCLIError):
    """Exception raised for database operation errors.

    Used when SQLite operations fail or database is corrupted.
    """
    pass

ValidationError

Bases: WeebCLIError

Exception raised for input validation failures.

Used when user input or configuration values are invalid.

Source code in weeb_cli/exceptions.py
class ValidationError(WeebCLIError):
    """Exception raised for input validation failures.

    Used when user input or configuration values are invalid.
    """
    pass

DependencyError

Bases: WeebCLIError

Exception raised for external dependency issues.

Used when required tools (FFmpeg, MPV, Aria2) are missing or fail.

Source code in weeb_cli/exceptions.py
class DependencyError(WeebCLIError):
    """Exception raised for external dependency issues.

    Used when required tools (FFmpeg, MPV, Aria2) are missing or fail.
    """
    pass

Übersicht

Benutzerdefinierte Exception-Hierarchie für strukturierte Fehlerbehandlung in Weeb CLI. Alle Exceptions erben von der WeebCLIError-Basisklasse.

Exception-Hierarchie

WeebCLIError (Basis)
├── ProviderError
├── DownloadError
├── NetworkError
├── AuthenticationError
├── DatabaseError
├── ValidationError
└── DependencyError

Verwendungsbeispiele

Exceptions auslösen

from weeb_cli.exceptions import ProviderError, DownloadError

# Nur mit Nachricht
raise ProviderError("Anime-Details konnten nicht abgerufen werden")

# Mit Fehlercode
raise ProviderError("Suche fehlgeschlagen", code="PROVIDER_001")

# Download-Fehler
raise DownloadError("Unzureichender Speicherplatz", code="DISK_FULL")

Exceptions abfangen

from weeb_cli.exceptions import (
    ProviderError, 
    NetworkError, 
    WeebCLIError
)

try:
    provider.search("anime")
except ProviderError as e:
    print(f"Provider-Fehler: {e.message} ({e.code})")
except NetworkError as e:
    print(f"Netzwerkfehler: {e.message}")
except WeebCLIError as e:
    print(f"Allgemeiner Fehler: {e}")

Spezifische Exception-Behandlung

from weeb_cli.exceptions import (
    AuthenticationError,
    DatabaseError,
    ValidationError
)

# Authentifizierung
try:
    tracker.authenticate()
except AuthenticationError as e:
    print(f"Authentifizierung fehlgeschlagen: {e.message}")
    # Erneut authentifizieren

# Datenbank
try:
    db.save_progress()
except DatabaseError as e:
    print(f"Datenbankfehler: {e.code}")
    # Wiederholen oder sichern

# Validierung
try:
    validate_input(user_input)
except ValidationError as e:
    print(f"Ungültige Eingabe: {e.message}")
    # Erneut abfragen

Exception-Typen

WeebCLIError

Basis-Exception für alle Weeb CLI-Fehler. Bietet strukturierte Fehlerbehandlung mit optionalen Fehlercodes.

Attribute: - message (str): Menschenlesbare Fehlermeldung - code (str): Optionaler Fehlercode zur Kategorisierung

ProviderError

Ausgelöst für Anime-Provider-bezogene Fehler: - Suchfehler - Anime-Details konnten nicht abgerufen werden - Episodenliste nicht verfügbar - Stream-Extraktionsfehler

DownloadError

Ausgelöst für Download-Operationsfehler: - Netzwerkprobleme während des Downloads - Unzureichender Speicherplatz - Ungültige Stream-URLs - Aria2/yt-dlp-Fehler

NetworkError

Ausgelöst für Netzwerkverbindungsprobleme: - HTTP-Anfragefehler - Verbindungs-Timeouts - DNS-Auflösungsfehler - Netzwerk nicht verfügbar

AuthenticationError

Ausgelöst für Tracker-Authentifizierungsfehler: - OAuth-Flow-Fehler - Ungültige Anmeldedaten - Token-Ablauf - API-Authentifizierungsfehler

DatabaseError

Ausgelöst für Datenbankoperationsfehler: - SQLite-Fehler - Datenbankbeschädigung - Migrationsfehler - Abfragefehler

ValidationError

Ausgelöst für Eingabevalidierungsfehler: - Ungültige Konfigurationswerte - Fehlerhafte Benutzereingabe - Ungültige Dateipfade - URL-Validierungsfehler

DependencyError

Ausgelöst für externe Abhängigkeitsprobleme: - Fehlende erforderliche Tools (FFmpeg, MPV, Aria2) - Tool-Ausführungsfehler - Versionsinkompatibilitäten - Installationsfehler

Fehlercodes

Häufige Fehlercodes, die in der gesamten Anwendung verwendet werden:

Code Exception Beschreibung
PROVIDER_001 ProviderError Suche fehlgeschlagen
PROVIDER_002 ProviderError Details-Abruf fehlgeschlagen
PROVIDER_003 ProviderError Stream-Extraktion fehlgeschlagen
DOWNLOAD_001 DownloadError Speicherplatz unzureichend
DOWNLOAD_002 DownloadError Download fehlgeschlagen
NETWORK_001 NetworkError Verbindungs-Timeout
AUTH_001 AuthenticationError OAuth fehlgeschlagen
DB_001 DatabaseError Abfrage fehlgeschlagen
VALIDATION_001 ValidationError Ungültige Eingabe
DEP_001 DependencyError Tool fehlt

Best Practices

  1. Spezifische Exceptions verwenden: Spezifische Exceptions vor allgemeinen abfangen
  2. Fehlercodes einschließen: Fehlercodes für Protokollierung und Debugging verwenden
  3. Kontext bereitstellen: Relevante Informationen in Fehlermeldungen einschließen
  4. Graceful behandeln: Fallback-Verhalten wenn möglich bereitstellen
  5. Fehler protokollieren: Exceptions mit vollem Kontext für Debugging protokollieren

API-Referenz

WeebCLIError

Bases: Exception

Base exception for all Weeb CLI errors.

Provides structured error handling with optional error codes for better error tracking and debugging.

Attributes:

Name Type Description
message str

Human-readable error message.

code str

Optional error code for categorization.

Source code in weeb_cli/exceptions.py
class WeebCLIError(Exception):
    """Base exception for all Weeb CLI errors.

    Provides structured error handling with optional error codes for
    better error tracking and debugging.

    Attributes:
        message (str): Human-readable error message.
        code (str): Optional error code for categorization.
    """

    def __init__(self, message: str = "", code: str = "") -> None:
        """Initialize exception with message and optional code.

        Args:
            message: Descriptive error message.
            code: Optional error code (e.g., 'PROVIDER_001').
        """
        self.message = message
        self.code = code
        super().__init__(f"{code}: {message}" if code else message)

__init__

__init__(message: str = '', code: str = '') -> None

Initialize exception with message and optional code.

Parameters:

Name Type Description Default
message str

Descriptive error message.

''
code str

Optional error code (e.g., 'PROVIDER_001').

''
Source code in weeb_cli/exceptions.py
def __init__(self, message: str = "", code: str = "") -> None:
    """Initialize exception with message and optional code.

    Args:
        message: Descriptive error message.
        code: Optional error code (e.g., 'PROVIDER_001').
    """
    self.message = message
    self.code = code
    super().__init__(f"{code}: {message}" if code else message)

ProviderError

Bases: WeebCLIError

Exception raised for anime provider-related errors.

Used when providers fail to search, fetch details, or extract streams.

Source code in weeb_cli/exceptions.py
class ProviderError(WeebCLIError):
    """Exception raised for anime provider-related errors.

    Used when providers fail to search, fetch details, or extract streams.
    """
    pass

DownloadError

Bases: WeebCLIError

Exception raised for download operation failures.

Used when downloads fail due to network issues, disk space, or invalid stream URLs.

Source code in weeb_cli/exceptions.py
class DownloadError(WeebCLIError):
    """Exception raised for download operation failures.

    Used when downloads fail due to network issues, disk space, or
    invalid stream URLs.
    """
    pass

NetworkError

Bases: WeebCLIError

Exception raised for network connectivity issues.

Used when HTTP requests fail or network is unavailable.

Source code in weeb_cli/exceptions.py
class NetworkError(WeebCLIError):
    """Exception raised for network connectivity issues.

    Used when HTTP requests fail or network is unavailable.
    """
    pass

AuthenticationError

Bases: WeebCLIError

Exception raised for tracker authentication failures.

Used when OAuth flows fail or credentials are invalid.

Source code in weeb_cli/exceptions.py
class AuthenticationError(WeebCLIError):
    """Exception raised for tracker authentication failures.

    Used when OAuth flows fail or credentials are invalid.
    """
    pass

DatabaseError

Bases: WeebCLIError

Exception raised for database operation errors.

Used when SQLite operations fail or database is corrupted.

Source code in weeb_cli/exceptions.py
class DatabaseError(WeebCLIError):
    """Exception raised for database operation errors.

    Used when SQLite operations fail or database is corrupted.
    """
    pass

ValidationError

Bases: WeebCLIError

Exception raised for input validation failures.

Used when user input or configuration values are invalid.

Source code in weeb_cli/exceptions.py
class ValidationError(WeebCLIError):
    """Exception raised for input validation failures.

    Used when user input or configuration values are invalid.
    """
    pass

DependencyError

Bases: WeebCLIError

Exception raised for external dependency issues.

Used when required tools (FFmpeg, MPV, Aria2) are missing or fail.

Source code in weeb_cli/exceptions.py
class DependencyError(WeebCLIError):
    """Exception raised for external dependency issues.

    Used when required tools (FFmpeg, MPV, Aria2) are missing or fail.
    """
    pass