streamweave-error
Error handling system for StreamWeave
Comprehensive error handling with multiple strategies and rich error context.
The streamweave-error package provides a comprehensive error handling system for StreamWeave pipelines and graphs. It includes error strategies, error actions, rich error context, and component information for effective error handling and debugging.
β¨ Key Features
- ErrorStrategy Enum: Multiple error handling strategies (Stop, Skip, Retry, Custom)
- ErrorAction Enum: Actions to take when errors occur (Stop, Skip, Retry)
- StreamError Type: Rich error type with context and component information
- ErrorContext: Detailed context about when and where errors occurred
- ComponentInfo: Component identification for error reporting
- PipelineError: Pipeline-specific error wrapper
π¦ Installation
Add this to your Cargo.toml:
[]
= "0.3.0"
π Quick Start
Basic Error Handling
use ;
// Configure error strategy
let strategy = Skip; // Skip errors and continue
// Create error context
let context = ErrorContext ;
// Create component info
let component = new;
// Create stream error
let error = new;
// Determine action based on strategy
let action = match strategy ;
π API Overview
ErrorStrategy
The ErrorStrategy enum defines how components should handle errors:
Stop Strategy:
- Default behavior
- Stops processing immediately when an error occurs
- Ensures data integrity by preventing partial results
Skip Strategy:
- Skips items that cause errors
- Continues processing remaining items
- Useful for data cleaning scenarios
Retry Strategy:
- Retries failed operations up to specified number of times
- Useful for transient failures (network timeouts, etc.)
- Stops after retry limit is exhausted
Custom Strategy:
- Allows fine-grained control over error handling
- Can base decisions on error type, context, or retry count
- Enables complex error handling logic
ErrorAction
The ErrorAction enum represents the action to take when an error occurs:
StreamError
The StreamError type provides rich error information:
ErrorContext
The ErrorContext struct provides detailed information about when and where an error occurred:
ComponentInfo
The ComponentInfo struct identifies the component that encountered an error:
π Usage Examples
Stop Strategy
Stop processing on first error (default behavior):
use ErrorStrategy;
let strategy = Stop;
// When an error occurs, processing stops immediately
// This ensures data integrity
Skip Strategy
Skip errors and continue processing:
use ErrorStrategy;
let strategy = Skip;
// Invalid items are skipped, processing continues
// Useful for data cleaning pipelines
Retry Strategy
Retry failed operations:
use ErrorStrategy;
let strategy = Retry;
// Retries up to 3 times before giving up
// Useful for transient failures like network timeouts
Custom Error Handler
Implement custom error handling logic:
use ;
let strategy = new_custom;
Creating Error Context
Create detailed error context for debugging:
use ;
// Create error context
let context = ErrorContext ;
// Create component info
let component = new;
// Create stream error
let error = new;
Error Propagation Patterns
Handle errors at different levels:
use ;
// Component-level error handling
// Pipeline-level error handling
π§ Configuration
Error strategies can be configured at multiple levels:
Component Level
use ErrorStrategy;
// Configure producer error handling
let producer = new
.with_config;
// Configure transformer error handling
let transformer = new
.with_config;
// Configure consumer error handling
let consumer = new
.with_config;
Pipeline Level
use PipelineBuilder;
use ErrorStrategy;
let pipeline = new
.producer
.transformer
.consumer
.with_error_strategy; // Pipeline-wide default
ποΈ Architecture
The error handling system integrates at multiple levels:
βββββββββββββββββββ
β Component ββββencounters errorβββ> StreamError
βββββββββββββββββββ β
β
βΌ
βββββββββββββββββββ ββββββββββββββββ
β ErrorStrategy ββββdeterminesβββ> β ErrorAction β
βββββββββββββββββββ ββββββββββββββββ
β β
β βΌ
β ββββββββββββββββ
ββββuses context fromβββ> β ErrorContext β
ββββββββββββββββ
π Error Handling
Error Strategies
Stop (Default):
- Ensures data integrity
- Prevents partial results
- Best for critical data processing
Skip:
- Allows partial results
- Continues processing
- Best for data cleaning and filtering
Retry:
- Handles transient failures
- Configurable retry count
- Best for network operations and external services
Custom:
- Maximum flexibility
- Can implement complex logic
- Best for domain-specific error handling
Error Context
Error context provides:
- Timestamp: When the error occurred
- Item: The item being processed (if available)
- Component Name: Human-readable component identifier
- Component Type: Type name for debugging
Component Information
Component info enables:
- Logging: Identify which component failed
- Metrics: Track errors per component
- Debugging: Locate source of errors
- Monitoring: Alert on component failures
β‘ Performance Considerations
- Zero-Cost Abstractions: Error strategies compile to efficient code
- Minimal Overhead: Error context creation is lightweight
- Clone Efficiency: Error types are designed for efficient cloning
- Send + Sync: All error types are thread-safe
π Examples
For more examples, see:
π Dependencies
streamweave-error depends on:
thiserror- Error trait implementationserde- Serialization supportserde_json- JSON serializationchrono- Timestamp support
π― Use Cases
The error handling system is used for:
- Data Validation: Skip invalid records while processing valid ones
- Network Operations: Retry transient network failures
- External Services: Handle service unavailability gracefully
- Data Cleaning: Skip malformed data and continue processing
- Critical Processing: Stop on errors to ensure data integrity
π Documentation
π See Also
- streamweave - Core traits that use error handling
- streamweave-pipeline - Pipeline error handling
- streamweave-graph - Graph error handling
π€ Contributing
Contributions are welcome! Please see the Contributing Guide for details.
π License
This project is licensed under the CC BY-SA 4.0 license.