tux.utils.exceptions
¶
Classes:
Name | Description |
---|---|
PermissionLevelError | Raised when a user doesn't have the required permission level. |
AppCommandPermissionLevelError | Raised when a user doesn't have the required permission level for an app command. |
APIConnectionError | Raised when there's an issue connecting to an external API. |
APIRequestError | Raised when an API request fails with a specific status code. |
APIResourceNotFoundError | Raised when an API request results in a 404 or similar resource not found error. |
APIPermissionError | Raised when an API request fails due to permissions (e.g., 403 Forbidden). |
CodeExecutionError | Base exception for code execution errors. |
MissingCodeError | Raised when no code is provided for execution. |
InvalidCodeFormatError | Raised when code format is invalid. |
UnsupportedLanguageError | Raised when the specified language is not supported. |
CompilationError | Raised when code compilation fails. |
Functions:
Name | Description |
---|---|
handle_gather_result | Handle a result from asyncio.gather with return_exceptions=True. |
handle_case_result | Handle a case result from asyncio.gather with return_exceptions=True. |
Classes¶
PermissionLevelError(permission: str)
¶
Bases: Exception
Raised when a user doesn't have the required permission level.
Source code in tux/utils/exceptions.py
AppCommandPermissionLevelError(permission: str)
¶
Bases: Exception
Raised when a user doesn't have the required permission level for an app command.
Source code in tux/utils/exceptions.py
APIConnectionError(service_name: str, original_error: Exception)
¶
Bases: Exception
Raised when there's an issue connecting to an external API.
Source code in tux/utils/exceptions.py
APIRequestError(service_name: str, status_code: int, reason: str)
¶
Bases: Exception
Raised when an API request fails with a specific status code.
Source code in tux/utils/exceptions.py
APIResourceNotFoundError(service_name: str, resource_identifier: str, status_code: int = 404)
¶
Bases: APIRequestError
Raised when an API request results in a 404 or similar resource not found error.
Source code in tux/utils/exceptions.py
APIPermissionError(service_name: str, status_code: int = 403)
¶
Bases: APIRequestError
Raised when an API request fails due to permissions (e.g., 403 Forbidden).
Source code in tux/utils/exceptions.py
MissingCodeError()
¶
Bases: CodeExecutionError
Raised when no code is provided for execution.
Source code in tux/utils/exceptions.py
InvalidCodeFormatError()
¶
Bases: CodeExecutionError
Raised when code format is invalid.
Source code in tux/utils/exceptions.py
UnsupportedLanguageError(language: str, supported_languages: list[str])
¶
Bases: CodeExecutionError
Raised when the specified language is not supported.
Initialize with language-specific error message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
language | str | The unsupported language that was requested. | required |
supported_languages | list[str] | List of supported language names. | required |
Source code in tux/utils/exceptions.py
def __init__(self, language: str, supported_languages: list[str]) -> None:
"""
Initialize with language-specific error message.
Parameters
----------
language : str
The unsupported language that was requested.
supported_languages : list[str]
List of supported language names.
"""
self.language = language
self.supported_languages = supported_languages
available_langs = ", ".join(supported_languages)
super().__init__(
f"No compiler found for `{language}`. The following languages are supported:\n```{available_langs}```",
)
Functions¶
CompilationError()
¶
Bases: CodeExecutionError
Raised when code compilation fails.
Source code in tux/utils/exceptions.py
Functions¶
handle_gather_result(result: T | BaseException, expected_type: type[T]) -> T
¶
Handle a result from asyncio.gather with return_exceptions=True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result | T | BaseException | The result from asyncio.gather | required |
expected_type | type[T] | The expected type of the result | required |
Returns:
Type | Description |
---|---|
T | The result if it matches the expected type |
Raises:
Type | Description |
---|---|
BaseException | If the result is an exception |
TypeError | If the result is not of the expected type |
Source code in tux/utils/exceptions.py
def 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
------
BaseException
If the result is an exception
TypeError
If the result is not of the expected type
"""
if isinstance(result, BaseException):
raise result
if not isinstance(result, expected_type):
msg = f"Expected {expected_type.__name__} but got {type(result).__name__}"
raise TypeError(msg)
return result
handle_case_result(case_result: Case | BaseException) -> Case
¶
Handle a case result from asyncio.gather with return_exceptions=True.
Text OnlyParameters
Parameters
case_result : Case | BaseException The case result from asyncio.gather
Returns:
Type | Description |
---|---|
Case | The case if valid |
Raises:
Type | Description |
---|---|
BaseException | If the result is an exception |
TypeError | If the result is not a Case |
Source code in tux/utils/exceptions.py
def handle_case_result(case_result: Case | BaseException) -> Case:
"""Handle a case result from asyncio.gather with return_exceptions=True.
Parameters
----------
case_result : Case | BaseException
The case result from asyncio.gather
Returns
-------
Case
The case if valid
Raises
------
BaseException
If the result is an exception
TypeError
If the result is not a Case
"""
return handle_gather_result(case_result, Case)