gwkokab.utils.exceptions¶

Custom Logged Exceptions and Warnings for gwkokab.

This module provides a registry of standard Python exceptions and warnings extended with automatic logging capabilities via loguru.

The mixin classes LoggedMixinException and LoggedMixinWarning provide the functionality to format and log messages for exceptions and warnings, respectively. The custom exception and warning classes inherit from these mixins and the corresponding built-in exception or warning classes. When an instance of these custom classes is created, the message is formatted using the provided arguments and keyword arguments, and then logged at the appropriate level (error for exceptions and warning for warnings). If formatting fails, the original message is used without formatting. This allows for consistent logging of error and warning messages throughout the application.

You can use these custom exceptions and warnings in your code to automatically log messages when they are raised or issued. For example:

import warnings

from gwkokab.utils.exceptions import LoggedMixinException, LoggedMixinWarning


class LoggedValueError(LoggedMixinException, ValueError):
    pass


class LoggedUserWarning(LoggedMixinWarning, UserWarning):
    pass


warnings.warn("This is a warning message", LoggedUserWarning)

raise LoggedValueError("Invalid value: {value}", value=42)

Exceptions¶

LoggedAssertionError

A mixin class for exceptions that logs the error message using loguru when the

LoggedDeprecationWarning

A mixin class for warnings that logs the warning message using loguru when the

LoggedImportError

A mixin class for exceptions that logs the error message using loguru when the

LoggedIndexError

A mixin class for exceptions that logs the error message using loguru when the

LoggedKeyError

A mixin class for exceptions that logs the error message using loguru when the

LoggedNotImplementedError

A mixin class for exceptions that logs the error message using loguru when the

LoggedRuntimeWarning

A mixin class for warnings that logs the warning message using loguru when the

LoggedTypeError

A mixin class for exceptions that logs the error message using loguru when the

LoggedUserWarning

A mixin class for warnings that logs the warning message using loguru when the

LoggedValueError

A mixin class for exceptions that logs the error message using loguru when the

Classes¶

LoggedMixinException

A mixin class for exceptions that logs the error message using loguru when the

LoggedMixinWarning

A mixin class for warnings that logs the warning message using loguru when the

Module Contents¶

exception gwkokab.utils.exceptions.LoggedAssertionError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinException, AssertionError

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedDeprecationWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinWarning, DeprecationWarning

A mixin class for warnings that logs the warning message using loguru when the warning is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the warning level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedImportError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinException, ImportError

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedIndexError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinException, IndexError

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedKeyError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinException, KeyError

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedNotImplementedError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinException, NotImplementedError

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedRuntimeWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinWarning, RuntimeWarning

A mixin class for warnings that logs the warning message using loguru when the warning is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the warning level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedTypeError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinException, TypeError

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedUserWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinWarning, UserWarning

A mixin class for warnings that logs the warning message using loguru when the warning is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the warning level.

Initialize self. See help(type(self)) for accurate signature.

exception gwkokab.utils.exceptions.LoggedValueError(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

Bases: LoggedMixinException, ValueError

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

Initialize self. See help(type(self)) for accurate signature.

class gwkokab.utils.exceptions.LoggedMixinException(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

A mixin class for exceptions that logs the error message using loguru when the exception is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the error level.

class gwkokab.utils.exceptions.LoggedMixinWarning(msg: str, *args, loguru_opt: dict[str, Any] = {'depth': 1}, **kwargs)[source]¶

A mixin class for warnings that logs the warning message using loguru when the warning is instantiated.

The message is formatted using the provided arguments and keyword arguments. If formatting fails, the original message is used without formatting. The formatted message is logged at the warning level.