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
__init__
¶
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
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
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
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
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
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
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
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
Ü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¶
- Spezifische Exceptions verwenden: Spezifische Exceptions vor allgemeinen abfangen
- Fehlercodes einschließen: Fehlercodes für Protokollierung und Debugging verwenden
- Kontext bereitstellen: Relevante Informationen in Fehlermeldungen einschließen
- Graceful behandeln: Fallback-Verhalten wenn möglich bereitstellen
- 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
__init__
¶
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
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
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
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
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
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
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
DependencyError
¶
Bases: WeebCLIError
Exception raised for external dependency issues.
Used when required tools (FFmpeg, MPV, Aria2) are missing or fail.