0ef5fcb1c5
Security / Dependency audit (pip-audit) (push) Has been cancelled
Security / CodeQL (javascript-typescript) (push) Has been cancelled
Security / CodeQL (python) (push) Has been cancelled
Security / Secret scan (gitleaks) (push) Has been cancelled
rust / test (ubuntu) (push) Has been cancelled
rust / simulator e2e (macos-latest) (push) Has been cancelled
rust / simulator e2e (ubuntu-latest) (push) Has been cancelled
rust / simulator e2e (windows-latest) (push) Has been cancelled
rust / wheels (aarch64-apple-darwin) (push) Has been cancelled
rust / wheels (x86_64-unknown-linux-gnu) (push) Has been cancelled
rust / wheels (x86_64-apple-darwin) (push) Has been cancelled
rust / audit (push) Has been cancelled
rust / parity (nightly, allowed to fail during Phase 0) (push) Has been cancelled
CI / commitlint (push) Has been skipped
Dev Containers / validate (.devcontainer/devcontainer.json, default) (push) Failing after 0s
Dev Containers / validate (.devcontainer/memory-stack/devcontainer.json, memory-stack) (push) Failing after 0s
Dev Containers / validate-worktree (push) Failing after 0s
CI / changes (push) Failing after 4s
Deploy Documentation / validate (push) Has been skipped
Deploy Documentation / deploy (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, claude) (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, codex) (push) Failing after 1s
Install Native E2E / install-native (ubuntu-latest) (push) Failing after 1s
OpenCode Plugin / typecheck + build + test (push) Failing after 1s
Init Native E2E / init-native (ubuntu-latest, copilot) (push) Failing after 1s
Release Please / release-please (push) Failing after 1s
Wrap E2E / docker-wrap-e2e (push) Failing after 1s
Wrap Native E2E / wrap-native (ubuntu-latest) (push) Failing after 1s
Init E2E / docker-init-e2e (push) Failing after 4s
Merge Conflicts / merge-conflicts (push) Failing after 4s
CI / lint (push) Has been cancelled
CI / build-wheel (push) Has been cancelled
CI / build-wheel-windows (push) Has been cancelled
CI / prefetch-model (push) Has been cancelled
CI / test-dashboard-ui (push) Has been cancelled
CI / test (1) (push) Has been cancelled
CI / test (2) (push) Has been cancelled
CI / test (3) (push) Has been cancelled
CI / test (4) (push) Has been cancelled
CI / test-extras (push) Has been cancelled
CI / test-agno (push) Has been cancelled
CI / build (push) Has been cancelled
CI / workflow-validation (push) Has been cancelled
CI / docker-native-e2e (push) Has been cancelled
CI / windows-native-wrapper (push) Has been cancelled
CI / macos-native-wrapper (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-manifest (map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-nonroot name:code-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim name:code-slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-code-slim-nonroot name:code-slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-nonroot name:nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim name:slim]) (push) Has been cancelled
Docker / docker-build (map[name:amd64 platform:linux/amd64 runs_on:ubuntu-24.04], map[bake_target:runtime-slim-nonroot name:slim-nonroot]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime name:]) (push) Has been cancelled
Docker / docker-build (map[name:arm64 platform:linux/arm64 runs_on:ubuntu-24.04-arm], map[bake_target:runtime-code name:code]) (push) Has been cancelled
Docker / promote-latest (push) Has been cancelled
Init Native E2E / init-native (macos-latest, claude) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, codex) (push) Has been cancelled
Init Native E2E / init-native (macos-latest, copilot) (push) Has been cancelled
Install Native E2E / install-native (macos-latest) (push) Has been cancelled
Wrap Native E2E / wrap-native (macos-latest) (push) Has been cancelled
193 lines
4.3 KiB
Python
193 lines
4.3 KiB
Python
"""Custom exceptions for Headroom.
|
|
|
|
This module provides explicit exception classes for better error handling
|
|
and debugging. All exceptions inherit from HeadroomError, making it easy
|
|
to catch all Headroom-related errors.
|
|
|
|
Example:
|
|
from headroom import HeadroomClient, HeadroomError, ConfigurationError
|
|
|
|
try:
|
|
client = HeadroomClient(...)
|
|
client.validate_setup()
|
|
except ConfigurationError as e:
|
|
print(f"Configuration problem: {e}")
|
|
except HeadroomError as e:
|
|
print(f"Headroom error: {e}")
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
class HeadroomError(Exception):
|
|
"""Base exception for all Headroom errors.
|
|
|
|
All Headroom exceptions inherit from this class, making it easy
|
|
to catch any Headroom-related error:
|
|
|
|
try:
|
|
client.chat.completions.create(...)
|
|
except HeadroomError as e:
|
|
# Handle any Headroom error
|
|
pass
|
|
"""
|
|
|
|
def __init__(self, message: str, details: dict[str, Any] | None = None):
|
|
super().__init__(message)
|
|
self.message = message
|
|
self.details = details or {}
|
|
|
|
def __str__(self) -> str:
|
|
if self.details:
|
|
detail_str = ", ".join(f"{k}={v}" for k, v in self.details.items())
|
|
return f"{self.message} ({detail_str})"
|
|
return self.message
|
|
|
|
|
|
class ConfigurationError(HeadroomError):
|
|
"""Raised when Headroom is misconfigured.
|
|
|
|
This includes:
|
|
- Invalid mode values
|
|
- Missing required configuration
|
|
- Incompatible configuration combinations
|
|
|
|
Example:
|
|
ConfigurationError(
|
|
"Invalid mode 'foo'",
|
|
details={"valid_modes": ["audit", "optimize"]}
|
|
)
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class ProviderError(HeadroomError):
|
|
"""Raised when there's an issue with the LLM provider.
|
|
|
|
This includes:
|
|
- Provider not recognized
|
|
- Provider-specific configuration issues
|
|
- Token counter errors
|
|
|
|
Example:
|
|
ProviderError(
|
|
"Unknown provider",
|
|
details={"provider": "foo", "known_providers": ["openai", "anthropic"]}
|
|
)
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class StorageError(HeadroomError):
|
|
"""Raised when there's an issue with metrics storage.
|
|
|
|
This includes:
|
|
- Database connection failures
|
|
- Invalid storage URL
|
|
- Write failures
|
|
|
|
Example:
|
|
StorageError(
|
|
"Cannot connect to database",
|
|
details={"url": "sqlite:///foo.db", "error": "Permission denied"}
|
|
)
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class CompressionError(HeadroomError):
|
|
"""Raised when compression fails.
|
|
|
|
This includes:
|
|
- Parse errors in tool outputs
|
|
- Invalid JSON structures
|
|
- Compression strategy failures
|
|
|
|
Example:
|
|
CompressionError(
|
|
"Failed to parse tool output",
|
|
details={"tool_name": "search_api", "content_preview": "..."}
|
|
)
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class TokenizationError(HeadroomError):
|
|
"""Raised when token counting fails.
|
|
|
|
This includes:
|
|
- Unknown model for tokenization
|
|
- Encoding errors
|
|
- Tiktoken/tokenizer loading failures
|
|
|
|
Example:
|
|
TokenizationError(
|
|
"Unknown model for tokenization",
|
|
details={"model": "gpt-99", "fallback_used": True}
|
|
)
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class CacheError(HeadroomError):
|
|
"""Raised when caching operations fail.
|
|
|
|
This includes:
|
|
- Cache store errors
|
|
- Retrieval failures
|
|
- CCR (Compress-Cache-Retrieve) errors
|
|
|
|
Example:
|
|
CacheError(
|
|
"Cache entry expired",
|
|
details={"hash": "abc123", "ttl": 300}
|
|
)
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class ValidationError(HeadroomError):
|
|
"""Raised when setup validation fails.
|
|
|
|
This is raised by validate_setup() when the configuration
|
|
or environment is not properly set up.
|
|
|
|
Example:
|
|
ValidationError(
|
|
"Setup validation failed",
|
|
details={
|
|
"provider_ok": True,
|
|
"storage_ok": False,
|
|
"storage_error": "Cannot write to database"
|
|
}
|
|
)
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class TransformError(HeadroomError):
|
|
"""Raised when a transform fails to apply.
|
|
|
|
This includes:
|
|
- SmartCrusher failures
|
|
- ContentRouter errors
|
|
- Pipeline errors
|
|
|
|
Example:
|
|
TransformError(
|
|
"Transform failed",
|
|
details={"transform": "smart_crusher", "reason": "..."}
|
|
)
|
|
"""
|
|
|
|
pass
|