mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-07-07 14:45:00 +00:00
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
"""Error types for Claude SDK."""
|
|
|
|
|
|
class ClaudeSDKError(Exception):
|
|
"""Base exception for all Claude SDK errors."""
|
|
|
|
|
|
class CLIConnectionError(ClaudeSDKError):
|
|
"""Raised when unable to connect to Claude Code."""
|
|
|
|
|
|
class CLINotFoundError(CLIConnectionError):
|
|
"""Raised when Claude Code is not found or not installed."""
|
|
|
|
def __init__(
|
|
self, message: str = "Claude Code not found", cli_path: str | None = None
|
|
):
|
|
if cli_path:
|
|
message = f"{message}: {cli_path}"
|
|
super().__init__(message)
|
|
|
|
|
|
class ProcessError(ClaudeSDKError):
|
|
"""Raised when the CLI process fails."""
|
|
|
|
def __init__(
|
|
self, message: str, exit_code: int | None = None, stderr: str | None = None
|
|
):
|
|
self.exit_code = exit_code
|
|
self.stderr = stderr
|
|
|
|
if exit_code is not None:
|
|
message = f"{message} (exit code: {exit_code})"
|
|
if stderr:
|
|
message = f"{message}\nError output: {stderr}"
|
|
|
|
super().__init__(message)
|
|
|
|
|
|
class CLIJSONDecodeError(ClaudeSDKError):
|
|
"""Raised when unable to decode JSON from CLI output."""
|
|
|
|
def __init__(self, line: str, original_error: Exception):
|
|
self.line = line
|
|
self.original_error = original_error
|
|
super().__init__(f"Failed to decode JSON: {line[:100]}...")
|