feat(lib): add errors module
Introduce AiMouseError base class plus ModelLoadError and GenerationError subclasses so downstream consumers can catch the umbrella or specific failure modes. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
18
src/ai_mouse/errors.py
Normal file
18
src/ai_mouse/errors.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Exception hierarchy for the ai_mouse library.
|
||||
|
||||
Downstream consumers can catch the umbrella :class:`AiMouseError`
|
||||
or the specific subclasses for finer control.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
class AiMouseError(Exception):
|
||||
"""Base class for all ai_mouse errors."""
|
||||
|
||||
|
||||
class ModelLoadError(AiMouseError):
|
||||
"""Raised when ONNX weights / metadata cannot be loaded."""
|
||||
|
||||
|
||||
class GenerationError(AiMouseError):
|
||||
"""Raised when inference produces an invalid result (e.g. NaN)."""
|
||||
19
tests/unit/test_errors.py
Normal file
19
tests/unit/test_errors.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""Test the error hierarchy."""
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from ai_mouse import errors
|
||||
|
||||
|
||||
def test_model_load_error_is_aimouse_error() -> None:
|
||||
assert issubclass(errors.ModelLoadError, errors.AiMouseError)
|
||||
|
||||
|
||||
def test_generation_error_is_aimouse_error() -> None:
|
||||
assert issubclass(errors.GenerationError, errors.AiMouseError)
|
||||
|
||||
|
||||
def test_can_catch_specific_with_general() -> None:
|
||||
with pytest.raises(errors.AiMouseError):
|
||||
raise errors.ModelLoadError("test")
|
||||
Reference in New Issue
Block a user