Error Handling

Bases: ValueError

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

Source code in utils\errors\errors.py
1
2
3
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
6
7
8
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
11
12
13
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
16
17
18
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
21
22
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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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