İstisnalar Modülü¶
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
Genel Bakış¶
Weeb CLI genelinde yapılandırılmış hata işleme için özel istisna hiyerarşisi. Tüm istisnalar WeebCLIError temel sınıfından türetilir.
İstisna Hiyerarşisi¶
WeebCLIError (temel)
├── ProviderError
├── DownloadError
├── NetworkError
├── AuthenticationError
├── DatabaseError
├── ValidationError
└── DependencyError
Kullanım Örnekleri¶
İstisna Fırlatma¶
from weeb_cli.exceptions import ProviderError, DownloadError
# Yalnızca mesajla
raise ProviderError("Anime detayları alınamadı")
# Hata koduyla
raise ProviderError("Arama başarısız", code="PROVIDER_001")
# İndirme hataları
raise DownloadError("Yetersiz disk alanı", code="DISK_FULL")
İstisnaları Yakalama¶
from weeb_cli.exceptions import (
ProviderError,
NetworkError,
WeebCLIError
)
try:
provider.search("anime")
except ProviderError as e:
print(f"Sağlayıcı hatası: {e.message} ({e.code})")
except NetworkError as e:
print(f"Ağ hatası: {e.message}")
except WeebCLIError as e:
print(f"Genel hata: {e}")
Belirli İstisna İşleme¶
from weeb_cli.exceptions import (
AuthenticationError,
DatabaseError,
ValidationError
)
# Kimlik doğrulama
try:
tracker.authenticate()
except AuthenticationError as e:
print(f"Kimlik doğrulama başarısız: {e.message}")
# Yeniden kimlik doğrula
# Veritabanı
try:
db.save_progress()
except DatabaseError as e:
print(f"Veritabanı hatası: {e.code}")
# Yeniden dene veya yedekle
# Doğrulama
try:
validate_input(user_input)
except ValidationError as e:
print(f"Geçersiz girdi: {e.message}")
# Tekrar iste
İstisna Türleri¶
WeebCLIError¶
Tüm Weeb CLI hataları için temel istisna. İsteğe bağlı hata kodlarıyla yapılandırılmış hata işleme sağlar.
Özellikler:
- message (str): İnsan tarafından okunabilir hata mesajı
- code (str): Kategorizasyon için isteğe bağlı hata kodu
ProviderError¶
Anime sağlayıcı ile ilgili hatalar için fırlatılır: - Arama başarısızlıkları - Anime detayları alınamadı - Bölüm listesi kullanılamıyor - Yayın çıkarma hataları
DownloadError¶
İndirme işlemi başarısızlıkları için fırlatılır: - İndirme sırasında ağ sorunları - Yetersiz disk alanı - Geçersiz yayın URL'leri - Aria2/yt-dlp hataları
NetworkError¶
Ağ bağlantısı sorunları için fırlatılır: - HTTP istek başarısızlıkları - Bağlantı zaman aşımları - DNS çözümleme hataları - Ağ kullanılamıyor
AuthenticationError¶
İzleyici kimlik doğrulama başarısızlıkları için fırlatılır: - OAuth akış hataları - Geçersiz kimlik bilgileri - Token süresi dolması - API kimlik doğrulama başarısızlıkları
DatabaseError¶
Veritabanı işlem hataları için fırlatılır: - SQLite hataları - Veritabanı bozulması - Migrasyon başarısızlıkları - Sorgu hataları
ValidationError¶
Girdi doğrulama başarısızlıkları için fırlatılır: - Geçersiz yapılandırma değerleri - Hatalı biçimlendirilmiş kullanıcı girişi - Geçersiz dosya yolları - URL doğrulama hataları
DependencyError¶
Harici bağımlılık sorunları için fırlatılır: - Eksik gerekli araçlar (FFmpeg, MPV, Aria2) - Araç yürütme başarısızlıkları - Sürüm uyumsuzlukları - Kurulum hataları
Hata Kodları¶
Uygulama genelinde kullanılan yaygın hata kodları:
| Kod | İstisna | Açıklama |
|---|---|---|
PROVIDER_001 |
ProviderError | Arama başarısız |
PROVIDER_002 |
ProviderError | Detay alma başarısız |
PROVIDER_003 |
ProviderError | Yayın çıkarma başarısız |
DOWNLOAD_001 |
DownloadError | Disk alanı yetersiz |
DOWNLOAD_002 |
DownloadError | İndirme başarısız |
NETWORK_001 |
NetworkError | Bağlantı zaman aşımı |
AUTH_001 |
AuthenticationError | OAuth başarısız |
DB_001 |
DatabaseError | Sorgu başarısız |
VALIDATION_001 |
ValidationError | Geçersiz girdi |
DEP_001 |
DependencyError | Araç eksik |
En İyi Uygulamalar¶
- Belirli İstisnalar Kullanın: Genel olanlardan önce belirli istisnaları yakalayın
- Hata Kodları Ekleyin: Günlükleme ve hata ayıklama için hata kodları kullanın
- Bağlam Sağlayın: Hata mesajlarına ilgili bilgileri ekleyin
- Zarif İşleyin: Mümkün olduğunda yedek davranış sağlayın
- Hataları Günlükleyin: Hata ayıklama için tam bağlamla istisnaları günlükleyin
API Referansı¶
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.