Skip to content

exceptions

Custom Exceptions for Tux Bot.

This module defines all custom exception classes used throughout the Tux Discord bot, including database errors, permission errors, API errors, and validation errors.

Classes:

Functions:

Classes

TuxConfigurationError

Bases: TuxError

Raised when there's a configuration issue.

TuxRuntimeError

Bases: TuxError

Raised when there's a runtime issue.

TuxDatabaseError

Bases: TuxError

Base exception for database-related errors.

TuxDatabaseConnectionError

Python
TuxDatabaseConnectionError(
    message: str = "Database connection failed", original_error: Exception | None = None
)

Bases: TuxDatabaseError

Raised when database connection fails.

Initialize the database connection error.

Parameters:

  • message (str, default: 'Database connection failed' ) –

    Error message, by default "Database connection failed".

  • original_error (Exception, default: None ) –

    The original exception that caused this error, by default None.

Functions

TuxDatabaseMigrationError

Bases: TuxDatabaseError

Raised when database migration fails.

TuxDatabaseQueryError

Bases: TuxDatabaseError

Raised when a database query fails.

TuxPermissionLevelError

Python
TuxPermissionLevelError(permission: str)

Bases: TuxPermissionError

Raised when a user doesn't have the required permission rank.

Initialize the permission level error.

Parameters:

  • permission (str) –

    The name of the required permission that was missing.

Functions

TuxAppCommandPermissionLevelError

Python
TuxAppCommandPermissionLevelError(permission: str)

Bases: TuxPermissionError

Raised when a user doesn't have the required permission rank for an app command.

Initialize the app command permission level error.

Parameters:

  • permission (str) –

    The name of the required permission that was missing for the app command.

Functions

TuxPermissionDeniedError

Python
TuxPermissionDeniedError(
    required_rank: int, user_rank: int, command_name: str | None = None
)

Bases: TuxPermissionError

Raised when a user doesn't have permission to run a command (dynamic system).

Initialize the permission denied error.

Parameters:

  • required_rank (int) –

    The minimum permission rank required to run the command.

  • user_rank (int) –

    The actual permission rank of the user.

  • command_name (str, default: None ) –

    The name of the command that was attempted, by default None.

Functions

TuxAPIError

Bases: TuxError

Base exception for API-related errors.

TuxAPIConnectionError

Python
TuxAPIConnectionError(service_name: str, original_error: Exception)

Bases: TuxAPIError

Raised when there's an issue connecting to an external API.

Initialize the API connection error.

Parameters:

  • service_name (str) –

    Name of the service that failed to connect.

  • original_error (Exception) –

    The original exception that caused the connection failure.

Functions

TuxAPIRequestError

Python
TuxAPIRequestError(service_name: str, status_code: int, reason: str)

Bases: TuxAPIError

Raised when an API request fails with a specific status code.

Initialize the API request error.

Parameters:

  • service_name (str) –

    Name of the service that the request failed for.

  • status_code (int) –

    HTTP status code of the failed request.

  • reason (str) –

    Reason for the request failure.

Functions

TuxAPIResourceNotFoundError

Python
TuxAPIResourceNotFoundError(
    service_name: str, resource_identifier: str, status_code: int = 404
)

Bases: TuxAPIRequestError

Raised when an API request results in a 404 or similar resource not found error.

Initialize the API resource not found error.

Parameters:

  • service_name (str) –

    Name of the service that was queried.

  • resource_identifier (str) –

    Identifier of the resource that was not found.

  • status_code (int, default: 404 ) –

    HTTP status code, by default 404.

Functions

TuxAPIPermissionError

Python
TuxAPIPermissionError(service_name: str, status_code: int = 403)

Bases: TuxAPIRequestError

Raised when an API request fails due to permissions (e.g., 403 Forbidden).

Initialize the API permission error.

Parameters:

  • service_name (str) –

    Name of the service that rejected the request.

  • status_code (int, default: 403 ) –

    HTTP status code, by default 403.

Functions

TuxCodeExecutionError

TuxMissingCodeError

Python
TuxMissingCodeError()

Bases: TuxCodeExecutionError

Raised when no code is provided for execution.

Initialize the missing code error with usage instructions.

Functions

TuxInvalidCodeFormatError

Python
TuxInvalidCodeFormatError()

Bases: TuxCodeExecutionError

Raised when code format is invalid.

Initialize the invalid code format error with usage instructions.

Functions

TuxUnsupportedLanguageError

Python
TuxUnsupportedLanguageError(language: str, supported_languages: list[str])

Bases: TuxCodeExecutionError

Raised when the specified language is not supported.

Initialize with language-specific error message.

Parameters:

  • language (str) –

    The unsupported language that was requested.

  • supported_languages (list[str]) –

    List of supported language names.

Functions

TuxCompilationError

Python
TuxCompilationError()

Bases: TuxCodeExecutionError

Raised when code compilation fails.

Initialize the compilation error with default message.

Functions

TuxServiceError

Bases: TuxError

Base exception for service-related errors.

TuxCogLoadError

TuxDependencyResolutionError

Bases: TuxHotReloadError

Raised when dependency resolution fails.

TuxFileWatchError

Bases: TuxHotReloadError

Raised when file watching fails.

TuxModuleReloadError

Bases: TuxHotReloadError

Raised when module reloading fails.

TuxHotReloadConfigurationError

Bases: TuxHotReloadError

Raised when hot reload configuration is invalid.

Functions

handle_gather_result

Python
handle_gather_result(result: T | BaseException, expected_type: type[T]) -> T

Handle a result from asyncio.gather with return_exceptions=True.

Parameters:

  • result (T | BaseException) –

    The result from asyncio.gather

  • expected_type (type[T]) –

    The expected type of the result

Returns:

  • T

    The result if it matches the expected type

Raises:

  • TypeError

    If the result is not of the expected type

handle_case_result

Python
handle_case_result(case_result: Case | BaseException) -> Case

Handle a case result from asyncio.gather with return_exceptions=True.

Parameters:

Returns:

  • Case

    The case if valid