models
models
¶
Data models for error classification.
Contains the dataclass models used throughout the error handling system.
This module provides: - ParsedCliError: Structured error from CLI JSON output - ErrorInfo: Machine-readable error metadata (Google AIP-193 inspired) - ClassifiedError: Single error with classification and metadata - ErrorChain: Error chain from symptom to root cause - ClassificationResult: Multi-error result with root cause identification
Classes¶
ClassificationInput
dataclass
¶
ClassificationInput(stdout='', stderr='', exit_code=None, exit_signal=None, exit_reason=None, exception=None, output_format=None)
Bundled inputs for ErrorClassifier.classify_execution().
Groups the execution result fields that the classifier needs, reducing the
method's parameter count from 8 to 2 (self + input). Callers can
still pass individual keyword arguments for backward compatibility.
ParsedCliError
dataclass
¶
A single error extracted from CLI JSON output.
Claude CLI returns structured JSON with an errors[] array:
{
"result": "...",
"errors": [
{"type": "system", "message": "Rate limit exceeded"},
{"type": "user", "message": "spawn claude ENOENT"}
],
"cost_usd": 0.05
}
This dataclass represents one item from that array.
Attributes:
| Name | Type | Description |
|---|---|---|
error_type |
Literal['system', 'user', 'tool']
|
Error type from CLI: "system", "user", "tool". |
message |
str
|
Human-readable error message. |
tool_name |
str | None
|
For tool errors, the name of the failed tool. |
metadata |
dict[str, Any]
|
Additional structured metadata from the error. |
ErrorInfo
dataclass
¶
Machine-readable error identification (Google AIP-193 inspired).
Provides structured metadata for programmatic error handling.
Example:
error_info = ErrorInfo(
reason="BINARY_NOT_FOUND",
domain="marianne.backend.claude_cli",
metadata={
"expected_binary": "claude",
"search_path": "/usr/bin:/usr/local/bin",
"suggestion": "Ensure claude CLI is installed and in PATH",
}
)
Attributes:
| Name | Type | Description |
|---|---|---|
reason |
str
|
UPPER_SNAKE_CASE identifier for the specific error reason. |
domain |
str
|
Service/component identifier (e.g., "marianne.backend.claude_cli"). |
metadata |
dict[str, str]
|
Dynamic contextual information as key-value pairs. |
Attributes¶
reason
instance-attribute
¶
UPPER_SNAKE_CASE identifier for the specific error reason. Example: "RATE_LIMIT_EXCEEDED", "BINARY_NOT_FOUND"
domain
instance-attribute
¶
Service/component identifier. Example: "marianne.backend.claude_cli", "marianne.execution"
metadata
class-attribute
instance-attribute
¶
Dynamic contextual information. Example: {"binary_path": "/usr/bin/claude", "exit_code": "127"}
ClassifiedError
dataclass
¶
ClassifiedError(category, message, error_code=UNKNOWN, original_error=None, exit_code=None, exit_signal=None, exit_reason=None, retriable=True, suggested_wait_seconds=None, error_info=None)
An error with its classification and metadata.
ClassifiedError combines high-level category (for retry logic) with specific error codes (for diagnostics and logging). The error_code provides stable identifiers for programmatic handling while category determines retry behavior.
ErrorChain
dataclass
¶
Represents a chain of errors from symptom to root cause.
When multiple errors occur, this class helps identify the actual root cause vs symptoms. For example, if ENOENT and rate limit both appear, ENOENT is likely the root cause (missing binary prevents any operation).
Attributes:
| Name | Type | Description |
|---|---|---|
errors |
list[ClassifiedError]
|
All errors in order of detection (first = earliest). |
root_cause |
ClassifiedError
|
The error identified as the most fundamental cause. |
symptoms |
list[ClassifiedError]
|
Errors that are likely consequences of the root cause. |
confidence |
float
|
0.0-1.0 confidence in root cause identification. |
ClassificationResult
dataclass
¶
ClassificationResult(primary, secondary=list(), raw_errors=list(), confidence=1.0, classification_method='structured')
Complete classification result with root cause and context.
This is the new result type from the classifier, providing access
to all detected errors while maintaining backward compatibility
through the primary attribute.
Example:
# New code - returns ClassificationResult
classification = classifier.classify(stdout, stderr, exit_code)
result = classification.primary # Backward compatible
# Access all errors
for error in classification.all_errors:
log.info(f"Error: {error.error_code.value} - {error.message}")
Attributes:
| Name | Type | Description |
|---|---|---|
primary |
ClassifiedError
|
The identified root cause error. |
secondary |
list[ClassifiedError]
|
Secondary/symptom errors for debugging. |
raw_errors |
list[ParsedCliError]
|
Original parsed errors from CLI JSON. |
confidence |
float
|
0.0-1.0 confidence in root cause identification. |
classification_method |
str
|
How classification was done. |
Attributes¶
secondary
class-attribute
instance-attribute
¶
Secondary/symptom errors for debugging.
raw_errors
class-attribute
instance-attribute
¶
Original parsed errors from CLI JSON.
confidence
class-attribute
instance-attribute
¶
0.0-1.0 confidence in root cause identification.
classification_method
class-attribute
instance-attribute
¶
How classification was done: "structured", "exit_code", "regex_fallback".
should_retry
property
¶
Whether to retry based on primary error (backward compatibility).
Functions¶
to_error_chain
¶
Convert to ErrorChain for detailed analysis.