Reviewer · Error Handling
Preserve error handling context
When handling exceptions, preserve the original error context and provide clear, actionable error messages. This helps with debugging and improves the developer experience. Key practices:
When handling exceptions, preserve the original error context and provide clear, actionable error messages. This helps with debugging and improves the developer experience. Key practices:
- Avoid swallowing exception details during serialization or logging
- Include specific information about what caused the error
- Use appropriate exception types for different error scenarios
- Consider adding fallback error representations
Example of good error handling:
def handle_task_error(exc):
try:
# Attempt full error serialization
return {
"error_type": type(exc).__name__,
"error_details": str(exc),
"traceback": "".join(format_exception(type(exc), exc, exc.__traceback__)),
}
except Exception:
# Fallback to basic error information if serialization fails
return {
"error_type": type(exc).__name__,
"error_message": str(exc),
"note": "Full error details unavailable - serialization failed"
}
This approach ensures that error information is preserved as much as possible, with a fallback mechanism when full details cannot be captured. It helps maintain debuggability while being robust against serialization or logging failures.