Skip to content

feat: Add projection validation and error recovery #162

@jwilger

Description

@jwilger

Context

During the implementation of multi-stream query patterns (#148), it was noted that projections should handle invalid or corrupted data gracefully. Currently, projections may panic or produce incorrect results if they encounter unexpected data.

Requirements

  1. Validation: Projections should validate incoming events
  2. Error Recovery: Continue processing valid events even if some are invalid
  3. Diagnostics: Report which events failed and why
  4. Idempotency: Support re-running projections safely

Proposed Solution

pub enum ProjectionError {
    InvalidEvent { event_id: EventId, reason: String },
    StateCorruption { details: String },
    // ...
}

pub struct ProjectionResult<T> {
    pub state: T,
    pub errors: Vec<ProjectionError>,
    pub processed_count: usize,
}

impl<T> ProjectionBuilder<T> {
    pub fn with_error_handler<F>(self, handler: F) -> Self 
    where F: Fn(ProjectionError) + Send + Sync + 'static {
        // ...
    }
}

Benefits

  • Resilient to data corruption
  • Better debugging and monitoring
  • Can process partial data sets
  • Production-ready error handling

Tasks

  • Design error types for projections
  • Add validation to projection functions
  • Implement error collection and reporting
  • Add recovery strategies (skip, retry, compensate)
  • Create tests for error scenarios
  • Document error handling patterns

Labels

  • enhancement
  • error-handling
  • production-readiness

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions