Skip to content

Exception Hierarchy

The stride.exceptions module defines domain exceptions for the STRIDE framework, ensuring precise error reporting and clear diagnostic messaging.


Overview

All framework exceptions derive from StrideError. Specific subclasses are raised to indicate missing optional dependencies, invalid dimensionalities, mathematical errors, or configuration issues:

flowchart TD
    StrideError["StrideError\n(Base Framework Exception)"] --> OptionalDependencyError["OptionalDependencyError\n(Missing extra: shap, tensorflow, etc.)"]
    StrideError --> DriftDetectionError["DriftDetectionError\n(Detection execution failures)"]
    StrideError --> DimensionalityError["DimensionalityError\n(Invalid feature shapes, e.g. D < 2)"]
    StrideError --> ConfigurationError["ConfigurationError\n(Invalid detector parameters)"]
from stride.exceptions import (
    StrideError,
    OptionalDependencyError,
    DriftDetectionError,
    DimensionalityError,
    ConfigurationError,
)

Exception Reference

Exception Base Class Trigger Condition
StrideError Exception Root exception for all errors raised within STRIDE.
OptionalDependencyError StrideError Raised when an optional extra (e.g. shap, tensorflow, hdbscan) is requested but not installed in the current environment.
DriftDetectionError StrideError Raised when drift calculations fail due to degenerate data streams or calculation divergence.
DimensionalityError StrideError Raised when input matrices violate algorithm dimension constraints (e.g. attempting 2D boundary projections with fewer than 2 features).
ConfigurationError StrideError Raised when invalid algorithm parameters or contradictory configurations are supplied.

API Specification

stride.exceptions

Domain exceptions for the STRIDE framework.

ConfigurationError

Bases: StrideError

Raised when invalid parameters or configurations are provided.

DimensionalityError

Bases: StrideError

Raised when input feature dimensions violate method constraints (e.g. n_features < 2).

DriftDetectionError

Bases: StrideError

Raised when drift detection calculation fails or inputs are invalid.

OptionalDependencyError

OptionalDependencyError(
    package_name, feature_name=None, extra_name=None
)

Bases: StrideError

Raised when an optional dependency (e.g. tensorflow, shap) is missing.

Initialize the missing dependency error.

Parameters:

Name Type Description Default
package_name str

Name of the missing PyPI dependency package.

required
feature_name str | None

High-level feature requiring the dependency.

None
extra_name str | None

Optional install extra target (e.g. stride-xai[xai]).

None
Source code in src/stride/exceptions.py
def __init__(
    self,
    package_name: str,
    feature_name: str | None = None,
    extra_name: str | None = None,
) -> None:
    """Initialize the missing dependency error.

    Args:
        package_name: Name of the missing PyPI dependency package.
        feature_name: High-level feature requiring the dependency.
        extra_name: Optional install extra target (e.g. `stride-xai[xai]`).
    """
    if feature_name is None:
        super().__init__(package_name)
        self.package_name = package_name
        self.feature_name = ""
        self.extra_name = ""
    else:
        self.package_name = package_name
        self.feature_name = feature_name
        self.extra_name = extra_name or package_name
        super().__init__(
            f"Feature '{feature_name}' requires optional dependency '{package_name}'. "
            f"Install it using: pip install stride-xai[{self.extra_name}] or pip install {package_name}"
        )

StrideError

Bases: Exception

Base exception for all STRIDE errors.