Przejdź do treści

Moduł wyjątków

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

Przegląd

Niestandardowa hierarchia wyjątków dla strukturalnej obsługi błędów w całym Weeb CLI. Wszystkie wyjątki dziedziczą z klasy bazowej WeebCLIError.

Hierarchia wyjątków

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

Przykłady użycia

Wyrzucanie wyjątków

from weeb_cli.exceptions import ProviderError, DownloadError

# Tylko z wiadomością
raise ProviderError("Nie udało się pobrać szczegółów anime")

# Z kodem błędu
raise ProviderError("Wyszukiwanie nie powiodło się", code="PROVIDER_001")

# Błędy pobierania
raise DownloadError("Niewystarczająca przestrzeń dyskowa", code="DISK_FULL")

Łapanie wyjątków

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

try:
    provider.search("anime")
except ProviderError as e:
    print(f"Błąd dostawcy: {e.message} ({e.code})")
except NetworkError as e:
    print(f"Błąd sieci: {e.message}")
except WeebCLIError as e:
    print(f"Ogólny błąd: {e}")

Specyficzna obsługa wyjątków

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

# Uwierzytelnianie
try:
    tracker.authenticate()
except AuthenticationError as e:
    print(f"Uwierzytelnianie nie powiodło się: {e.message}")
    # Ponowne uwierzytelnienie

# Baza danych
try:
    db.save_progress()
except DatabaseError as e:
    print(f"Błąd bazy danych: {e.code}")
    # Ponów próbę lub utwórz kopię zapasową

# Walidacja
try:
    validate_input(user_input)
except ValidationError as e:
    print(f"Nieprawidłowe dane wejściowe: {e.message}")
    # Zapytaj ponownie

Typy wyjątków

WeebCLIError

Bazowy wyjątek dla wszystkich błędów Weeb CLI. Zapewnia strukturalną obsługę błędów z opcjonalnymi kodami błędów.

Atrybuty: - message (str): Czytelna dla człowieka wiadomość o błędzie - code (str): Opcjonalny kod błędu do kategoryzacji

ProviderError

Wyrzucany dla błędów związanych z dostawcą anime: - Niepowodzenia wyszukiwania - Nie udało się pobrać szczegółów anime - Lista odcinków niedostępna - Błędy ekstrakcji strumienia

DownloadError

Wyrzucany dla niepowodzeń operacji pobierania: - Problemy sieciowe podczas pobierania - Niewystarczająca przestrzeń dyskowa - Nieprawidłowe adresy URL strumieni - Błędy Aria2/yt-dlp

NetworkError

Wyrzucany dla problemów z połączeniem sieciowym: - Niepowodzenia żądań HTTP - Przekroczenia limitu czasu połączenia - Błędy rozwiązywania DNS - Sieć niedostępna

AuthenticationError

Wyrzucany dla niepowodzeń uwierzytelniania trackera: - Błędy przepływu OAuth - Nieprawidłowe poświadczenia - Wygaśnięcie tokenu - Niepowodzenia uwierzytelniania API

DatabaseError

Wyrzucany dla błędów operacji bazy danych: - Błędy SQLite - Uszkodzenie bazy danych - Niepowodzenia migracji - Błędy zapytań

ValidationError

Wyrzucany dla niepowodzeń walidacji danych wejściowych: - Nieprawidłowe wartości konfiguracji - Źle sformatowane dane wejściowe użytkownika - Nieprawidłowe ścieżki plików - Błędy walidacji URL

DependencyError

Wyrzucany dla problemów z zależnościami zewnętrznymi: - Brakujące wymagane narzędzia (FFmpeg, MPV, Aria2) - Niepowodzenia wykonania narzędzi - Niezgodności wersji - Błędy instalacji

Kody błędów

Typowe kody błędów używane w całej aplikacji:

Kod Wyjątek Opis
PROVIDER_001 ProviderError Wyszukiwanie nie powiodło się
PROVIDER_002 ProviderError Pobieranie szczegółów nie powiodło się
PROVIDER_003 ProviderError Ekstrakcja strumienia nie powiodła się
DOWNLOAD_001 DownloadError Niewystarczająca przestrzeń dyskowa
DOWNLOAD_002 DownloadError Pobieranie nie powiodło się
NETWORK_001 NetworkError Przekroczenie limitu czasu połączenia
AUTH_001 AuthenticationError OAuth nie powiodło się
DB_001 DatabaseError Zapytanie nie powiodło się
VALIDATION_001 ValidationError Nieprawidłowe dane wejściowe
DEP_001 DependencyError Brakujące narzędzie

Najlepsze praktyki

  1. Używaj specyficznych wyjątków: Łap specyficzne wyjątki przed ogólnymi
  2. Dołączaj kody błędów: Używaj kodów błędów do logowania i debugowania
  3. Zapewnij kontekst: Dołącz istotne informacje w wiadomościach o błędach
  4. Obsługuj łagodnie: Zapewnij zachowanie awaryjne, gdy to możliwe
  5. Loguj błędy: Loguj wyjątki z pełnym kontekstem do debugowania

Dokumentacja API

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