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

AssertionError that logs its message at ERROR level when raised.

LoggedAttributeError

AttributeError that logs its message at ERROR level when raised.

LoggedDeprecationWarning

DeprecationWarning that logs its message at WARNING level when

LoggedFileNotFoundError

FileNotFoundError that logs its message at ERROR level when

LoggedImportError

ImportError that logs its message at ERROR level when raised.

LoggedIndexError

IndexError that logs its message at ERROR level when raised.

LoggedKeyError

KeyError that logs its message at ERROR level when raised.

LoggedNotImplementedError

NotImplementedError that logs its message at ERROR level when

LoggedRuntimeWarning

RuntimeWarning that logs its message at WARNING level when

LoggedTypeError

TypeError that logs its message at ERROR level when raised.

LoggedUserWarning

UserWarning that logs its message at WARNING level when issued.

LoggedValueError

ValueError that logs its message at ERROR level when raised.

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

AssertionError that logs its message at ERROR level when raised.

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

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

Bases: LoggedMixinException, AttributeError

AttributeError that logs its message at ERROR level when raised.

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

DeprecationWarning that logs its message at WARNING level when issued.

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

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

Bases: LoggedMixinException, FileNotFoundError

FileNotFoundError that logs its message at ERROR level when raised.

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

ImportError that logs its message at ERROR level when raised.

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

IndexError that logs its message at ERROR level when raised.

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

KeyError that logs its message at ERROR level when raised.

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

NotImplementedError that logs its message at ERROR level when raised.

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

RuntimeWarning that logs its message at WARNING level when issued.

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

TypeError that logs its message at ERROR level when raised.

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

UserWarning that logs its message at WARNING level when issued.

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

ValueError that logs its message at ERROR level when raised.

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.

Parameters:
  • msg (str) – Message template, using loguru’s {}-style formatting.

  • *args (Any) – Positional arguments substituted into msg.

  • loguru_opt (dict[str, Any], optional) – Options forwarded to loguru.Logger.opt(). Defaults to {"depth": 1} so the log record points at the caller that raised the exception rather than at this mixin.

  • **kwargs (Any) – Keyword arguments substituted into msg.

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.

Parameters:
  • msg (str) – Message template, using loguru’s {}-style formatting.

  • *args (Any) – Positional arguments substituted into msg.

  • loguru_opt (dict[str, Any], optional) – Options forwarded to loguru.Logger.opt(). Defaults to {"depth": 1} so the log record points at the caller that issued the warning rather than at this mixin.

  • **kwargs (Any) – Keyword arguments substituted into msg.