Mechanical only, and separated from the judgment calls that follow so the reviewable changes are not buried in a 98-file whitespace diff. 227 automatic fixes: 60 blank lines carrying whitespace, 60 unsorted import blocks, 34 Optional[X] to X | None, 28 unused imports, 16 deprecated typing imports, 12 datetime.timezone.utc to datetime.UTC, and assorted smaller modernisations. Then `ruff format` over src and tests: 98 files reformatted, 35 already conforming. No file among the unused-import findings defines __all__ or is an __init__.py, so nothing here removes a re-export. `make test`: 658 passed, unchanged from HEAD. Two things observed while verifying, neither addressed here: `pytest tests/` cannot collect — tests/e2e/test_orchestration_e2e.py uses an `e2e` marker that is not registered, and the config is strict about markers. This fails identically at HEAD, so it predates this change; `make test` passes because it ignores tests/e2e, tests/integration and tests/contracts. test_tatlock_tool_call_logging_calculator is flaky. It failed once in a full run with these changes and passed on the next, passes in isolation with them, and fails in isolation at HEAD. It is order- or timing-dependent, not a regression from this commit — established by running the full suite both ways rather than by reasoning about which change could have caused it. Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
2.1 KiB
Python
75 lines
2.1 KiB
Python
"""
|
|
Global exception definitions.
|
|
Domain-specific exceptions should be in their respective modules.
|
|
"""
|
|
|
|
from typing import Any
|
|
|
|
|
|
class AppException(Exception):
|
|
"""Base exception for all application errors."""
|
|
|
|
def __init__(
|
|
self,
|
|
message: str = "An error occurred",
|
|
status_code: int = 500,
|
|
details: dict[str, Any] | None = None,
|
|
):
|
|
self.message = message
|
|
self.status_code = status_code
|
|
self.details = details or {}
|
|
super().__init__(self.message)
|
|
|
|
|
|
class OllamaConnectionError(AppException):
|
|
"""Raised when cannot connect to Ollama service."""
|
|
|
|
def __init__(self, message: str = "Cannot connect to Ollama service"):
|
|
super().__init__(message=message, status_code=503)
|
|
|
|
|
|
class OllamaTimeoutError(AppException):
|
|
"""Raised when Ollama request times out."""
|
|
|
|
def __init__(self, message: str = "Ollama request timed out"):
|
|
super().__init__(message=message, status_code=504)
|
|
|
|
|
|
class ModelNotFoundError(AppException):
|
|
"""Raised when requested model is not available."""
|
|
|
|
def __init__(self, model_name: str):
|
|
super().__init__(
|
|
message=f"Model '{model_name}' not found",
|
|
status_code=404,
|
|
details={"model": model_name},
|
|
)
|
|
|
|
|
|
class ValidationError(AppException):
|
|
"""Raised for validation errors."""
|
|
|
|
def __init__(self, message: str, details: dict[str, Any] | None = None):
|
|
super().__init__(message=message, status_code=422, details=details)
|
|
|
|
|
|
class RateLimitError(AppException):
|
|
"""Raised when rate limit is exceeded."""
|
|
|
|
def __init__(self, message: str = "Rate limit exceeded"):
|
|
super().__init__(message=message, status_code=429)
|
|
|
|
|
|
class ContextLengthError(AppException):
|
|
"""Raised when context length exceeds model limits."""
|
|
|
|
def __init__(self, message: str = "Context length exceeded"):
|
|
super().__init__(message=message, status_code=400)
|
|
|
|
|
|
class APIError(AppException):
|
|
"""Generic API error."""
|
|
|
|
def __init__(self, message: str, status_code: int = 500):
|
|
super().__init__(message=message, status_code=status_code)
|