Files
yvgude--lean-ctx/clients/python/leanctx/errors.py
T
wehub-resource-sync 26382a7ac6
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
JetBrains Plugin / Actionlint (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
CodeQL / Analyze (rust) (push) Waiting to run
JetBrains Plugin / Validation (push) Waiting to run
JetBrains Plugin / Build (push) Waiting to run
JetBrains Plugin / Test (push) Blocked by required conditions
Security Check / Security Scan (push) Waiting to run
CI / Clippy (push) Failing after 15m13s
CI / Test (ubuntu-latest) (push) Failing after 16m1s
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Build (no embeddings / no ORT) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Cookbook (Node) (push) Has been cancelled
CI / Pi Extension (Node) (push) Has been cancelled
CI / Rust SDK (lean-ctx-client) (push) Has been cancelled
CI / Embed SDK (lean-ctx-sdk) (push) Has been cancelled
CI / Python SDK (leanctx) (push) Has been cancelled
CI / Hermes Plugin (Python) (push) Has been cancelled
CI / SDK Conformance Matrix (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / cargo-deny (push) Has been cancelled
CI / Adversarial Safety (push) Has been cancelled
CI / Benchmarks (push) Has been cancelled
CI / Output-Quality Gate (eval A/B) (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / CI Green (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:35:30 +08:00

48 lines
1.3 KiB
Python

"""Error types for the lean-ctx Python client."""
from __future__ import annotations
from typing import Any, Optional
class LeanCtxError(Exception):
"""Base class for all lean-ctx client errors."""
class LeanCtxConfigError(LeanCtxError):
"""Raised for invalid client configuration or arguments (no I/O performed)."""
class LeanCtxTransportError(LeanCtxError):
"""Raised when the request never produced an HTTP response (network/DNS/TLS)."""
class LeanCtxHTTPError(LeanCtxError):
"""Raised for a non-2xx HTTP response from the server.
Carries enough structured detail (status, method, url, server error code and
body) for programmatic handling, mirroring the Rust/TS SDK error shape.
"""
def __init__(
self,
*,
status: int,
method: str,
url: str,
message: str,
error_code: Optional[str] = None,
body: Any = None,
) -> None:
super().__init__(message)
self.status = status
self.method = method
self.url = url
self.message = message
self.error_code = error_code
self.body = body
def __str__(self) -> str: # pragma: no cover - trivial
code = f" [{self.error_code}]" if self.error_code else ""
return f"HTTP {self.status} {self.method} {self.url}{code}: {self.message}"