Skip to content

Exceptions Module

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

Overview

Custom exception hierarchy for structured error handling throughout Weeb CLI. All exceptions inherit from WeebCLIError base class.

Exception Hierarchy

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

Usage Examples

Raising Exceptions

from weeb_cli.exceptions import ProviderError, DownloadError

# With message only
raise ProviderError("Failed to fetch anime details")

# With error code
raise ProviderError("Search failed", code="PROVIDER_001")

# Download errors
raise DownloadError("Insufficient disk space", code="DISK_FULL")

Catching Exceptions

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

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

Specific Exception Handling

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

# Authentication
try:
    tracker.authenticate()
except AuthenticationError as e:
    print(f"Auth failed: {e.message}")
    # Re-authenticate

# Database
try:
    db.save_progress()
except DatabaseError as e:
    print(f"Database error: {e.code}")
    # Retry or backup

# Validation
try:
    validate_input(user_input)
except ValidationError as e:
    print(f"Invalid input: {e.message}")
    # Prompt again

Exception Types

WeebCLIError

Base exception for all Weeb CLI errors. Provides structured error handling with optional error codes.

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

ProviderError

Raised for anime provider-related errors: - Search failures - Failed to fetch anime details - Episode list unavailable - Stream extraction errors

DownloadError

Raised for download operation failures: - Network issues during download - Insufficient disk space - Invalid stream URLs - Aria2/yt-dlp errors

NetworkError

Raised for network connectivity issues: - HTTP request failures - Connection timeouts - DNS resolution errors - Network unavailable

AuthenticationError

Raised for tracker authentication failures: - OAuth flow errors - Invalid credentials - Token expiration - API authentication failures

DatabaseError

Raised for database operation errors: - SQLite errors - Database corruption - Migration failures - Query errors

ValidationError

Raised for input validation failures: - Invalid configuration values - Malformed user input - Invalid file paths - URL validation errors

DependencyError

Raised for external dependency issues: - Missing required tools (FFmpeg, MPV, Aria2) - Tool execution failures - Version incompatibilities - Installation errors

Error Codes

Common error codes used throughout the application:

Code Exception Description
PROVIDER_001 ProviderError Search failed
PROVIDER_002 ProviderError Details fetch failed
PROVIDER_003 ProviderError Stream extraction failed
DOWNLOAD_001 DownloadError Disk space insufficient
DOWNLOAD_002 DownloadError Download failed
NETWORK_001 NetworkError Connection timeout
AUTH_001 AuthenticationError OAuth failed
DB_001 DatabaseError Query failed
VALIDATION_001 ValidationError Invalid input
DEP_001 DependencyError Tool missing

Best Practices

  1. Use Specific Exceptions: Catch specific exceptions before general ones
  2. Include Error Codes: Use error codes for logging and debugging
  3. Provide Context: Include relevant information in error messages
  4. Handle Gracefully: Provide fallback behavior when possible
  5. Log Errors: Log exceptions with full context for debugging

API Reference

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