Source code for fieldview.exceptions

"""FieldView-specific exception hierarchy."""

from __future__ import annotations

import importlib

__all__ = [
    "FieldViewError",
    "InvalidArgumentError",
    "InvalidDatasetError",
    "CoreError",
]


def _send_fv_error_msg(message: str, header: str = "PyFieldView Error") -> None:
    """Best-effort bridge to the FieldView UI error dialog."""
    hint = "For more details, close this dialog and see the console."
    if hint.lower() in message.lower():
        popup_message = message
    else:
        popup_message = f"{message}\n\n{hint}"
    try:
        core = importlib.import_module("fieldview._core")
        func = getattr(core, "error_msg", None)
        if callable(func):
            func(popup_message, header)
    except Exception:
        pass


[docs] class FieldViewError(Exception): """Base error for the FieldView Python API.""" _popup_header = "PyFieldView Error" def __init__(self, message: str = "", *, show_popup: bool = True) -> None: super().__init__(message) if show_popup: text = str(message).strip() if not text: text = f"Unexpected {type(self).__name__}." _send_fv_error_msg(text, header=self._popup_header)
[docs] class InvalidArgumentError(FieldViewError): """Invalid argument or value supplied."""
[docs] class InvalidDatasetError(FieldViewError): """Dataset is invalid, missing, or not loaded."""
[docs] class CoreError(FieldViewError): """Core/engine call failed."""