Error Handling

Bases: ValueError

Raised when an open-circuit voltage (Voc) value cannot be located.

Source code in utils/errors/errors.py
class VocNotFoundError(ValueError):
    """Raised when an open-circuit voltage (Voc) value cannot be located."""
    pass

Bases: ValueError

Raised when a short-circuit current (Isc) value cannot be located.

Source code in utils/errors/errors.py
class IscNotFoundError(ValueError):
    """Raised when a short-circuit current (Isc) value cannot be located."""
    pass

Bases: ValueError

Raised when a requested observable cannot be derived from the available data.

Source code in utils/errors/errors.py
class ObservableNotComputableError(ValueError):
    """Raised when a requested observable cannot be derived from the available data."""
    pass

Bases: KeyError

Raised when a dataset or configuration refers to an unknown device type.

Source code in utils/errors/errors.py
class IncompatibleDeviceTypeFound(KeyError):
    """Raised when a dataset or configuration refers to an unknown device type."""
    pass

Bases: RuntimeError

Raised when the implementations package fails validation.

Source code in utils/errors/errors.py
class ImplementationError(RuntimeError):
    """Raised when the implementations package fails validation."""

Wrap a function so that :class:VocNotFoundError is logged and suppressed.

Parameters

func: Callable to execute. logger: Logger instance used to record the error.

Returns

Callable[..., Any] A wrapper that calls func and logs any :class:VocNotFoundError instead of propagating it.

Source code in utils/errors/logging.py
def error_with_logging(func: Callable[..., Any], logger: logging.Logger) -> Callable[..., Any]:
    """
    Wrap a function so that :class:`VocNotFoundError` is logged and suppressed.

    Parameters
    ----------
    func:
        Callable to execute.
    logger:
        Logger instance used to record the error.

    Returns
    -------
    Callable[..., Any]
        A wrapper that calls ``func`` and logs any :class:`VocNotFoundError`
        instead of propagating it.
    """
    @functools.wraps(func)
    def wrapper(*args: Any, **kwargs: Any) -> Any:
        try:
            func(*args, **kwargs)
        except VocNotFoundError as err:
            logger.error(f"Found error {err} calling {func.__name__}")

    return wrapper

Decorator that logs and re-raises any exception raised by func.

Parameters

func: Callable to wrap. logger: Logger instance used to record the exception and traceback.

Returns

Callable[..., Any] A wrapper that logs the exception details before re-raising them.

Source code in utils/errors/logging.py
def exceptions_logging(func: Callable[..., Any], logger: logging.Logger) -> Callable[..., Any]:
    """
    Decorator that logs and re-raises any exception raised by ``func``.

    Parameters
    ----------
    func:
        Callable to wrap.
    logger:
        Logger instance used to record the exception and traceback.

    Returns
    -------
    Callable[..., Any]
        A wrapper that logs the exception details before re-raising them.
    """
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            func(*args, **kwargs)
        except Exception as exc:
            import traceback
            logger.error(f"Found error {exc} calling {func.__name__}")
            logger.error(f"Reported trace: {traceback.format_exc()}")

            raise
    return wrapper