error-handlinglisted
Install: claude install-skill andr-ca/agentharness
# Error Handling & Recovery
Structured approaches to errors, recovery, and observability. **Never silently hide errors.**
## Core Patterns
### 1. Explicit Errors (Always)
Return errors as values or raise them; never ignore them.
```python
# ✅ Good: Explicit handling
try:
user = parse_user_data(raw)
except json.JSONDecodeError as e:
# Never log the raw payload — it can carry passwords/PII. Log a
# bounded, redaction-safe summary instead.
logger.error("Invalid user JSON", extra={"error": str(e), "payload_length": len(raw)})
return None
# ❌ Bad: Silent failure
try:
parse_user_data(raw)
except:
pass # User data silently ignored
```
### 2. Error Wrapping (Across Boundaries)
Add context as errors propagate—original error + where + why.
```python
# ✅ Python: Preserve cause
try:
return repository.find(user_id)
except DatabaseError as e:
raise UserNotFoundError(f"find user {user_id}") from e
# ✅ Go: Wrap with context
user, err := repo.Find(userID)
if err != nil {
return nil, fmt.Errorf("find user %s: %w", userID, err)
}
```
### 3. Error Classification
Decide recovery strategy based on error type.
```python
def classify_error(error):
if isinstance(error, (ConnectionError, TimeoutError)):
return "transient" # Retry
elif isinstance(error, (ValueError, KeyError)):
return "validation" # Reject, don't retry
else:
return "unknown"
# Transient �� retry with backoff
# Validation → log and fail
# Fatal → p