Skip to content

sudapy.core.errors

Custom exceptions with user-friendly hints.

sudapy.core.errors

Custom exceptions for SudaPy.

SudaPyError

Bases: Exception

Base exception for all SudaPy errors.

Source code in src\sudapy\core\errors.py
class SudaPyError(Exception):
    """Base exception for all SudaPy errors."""

    def __init__(self, message: str, hint: str | None = None) -> None:
        self.hint = hint
        full = message
        if hint:
            full += f"\n  Hint: {hint}"
        super().__init__(full)

CRSError

Bases: SudaPyError

Raised for CRS-related issues (invalid EPSG, unsupported datum, etc.).

Source code in src\sudapy\core\errors.py
class CRSError(SudaPyError):
    """Raised for CRS-related issues (invalid EPSG, unsupported datum, etc.)."""

FileFormatError

Bases: SudaPyError

Raised when an input file has an unsupported or invalid format.

Source code in src\sudapy\core\errors.py
class FileFormatError(SudaPyError):
    """Raised when an input file has an unsupported or invalid format."""

DependencyError

Bases: SudaPyError

Raised when a required optional dependency is missing.

Source code in src\sudapy\core\errors.py
class DependencyError(SudaPyError):
    """Raised when a required optional dependency is missing."""

check_import

check_import(module: str, extra: str = '') -> None

Import module or raise :class:DependencyError with install hint.

Parameters:

Name Type Description Default
module str

Dotted module name.

required
extra str

The pip extra that provides this module (e.g. "viz").

''
Source code in src\sudapy\core\errors.py
def check_import(module: str, extra: str = "") -> None:
    """Import *module* or raise :class:`DependencyError` with install hint.

    Args:
        module: Dotted module name.
        extra: The pip extra that provides this module (e.g. ``"viz"``).
    """
    try:
        __import__(module)
    except ImportError as exc:
        hint = f'pip install "sudapy[{extra}]"' if extra else f"pip install {module}"
        raise DependencyError(
            f"Missing dependency: {module}",
            hint=hint,
        ) from exc