burstError Handling

Error handling implements robust recovery patterns without introducing new primitives beyond Nodes and Events.

Core Principles

Happen's approach to error handling is built on these fundamental principles:

  1. Errors as Flow Branches: Errors are treated as natural branches in the event flow

  2. Functional Error Handling: Error handlers are just functions that can be returned

  3. Context for Error Information: Error details flow through context between functions

  4. Causal Error Tracking: Errors maintain causal relationships like normal events

  5. Decentralized Recovery: Nodes make local recovery decisions when possible

This approach achieves remarkable power with minimal complexity by leveraging existing primitives rather than introducing special error-handling constructs.

The Functional Error Model

In Happen, error handling is fully integrated into the Event Continuum through function returns:

// Register an event handler
orderNode.on("process-order", function validateOrder(event, context) {
  // Validate the order
  const validation = validateOrderData(event.payload);
  
  if (!validation.valid) {
    // Return error handler function on validation failure
    return handleInvalidOrder;
  }
  
  // Proceed with valid order
  context.validated = true;
  return processOrder;
});

// Error handler function
function handleInvalidOrder(event, context) {
  // Log the validation failure
  logValidationFailure(event.payload);
  
  // Return error result
  return {
    success: false,
    reason: "validation-failed",
    details: "Invalid order data"
  };
}

This functional approach means:

  1. Errors are just another branch in the flow

  2. Error handlers are regular functions

  3. Error information flows through context

  4. No special syntax or constructs are needed

Error Propagation and Context

Error information naturally flows through context:

This approach allows error information to flow naturally through the event chain, maintaining complete context for diagnostics and recovery.

Recovery Patterns

Happen's functional approach enables powerful recovery patterns through composition.

Retry Pattern

Circuit Breaker Pattern

Fallback Pattern

Error Events as First-Class Citizens

In Happen, errors can also be treated as normal events, enabling system-wide error handling:

Distributed Error Handling

When errors cross node boundaries, they naturally maintain their causal context:

Supervisor Pattern

For system-wide resilience, you can create supervisor nodes that monitor and manage error recovery:

Composing Error Handling with Normal Flow

Error handling in Happen integrates seamlessly with normal event processing:

Treating errors as branches in the functional flow provides sophisticated error handling capabilities without introducing special constructs.

Key takeaways:

  1. Use Function Returns for Error Flow: Return error handler functions to handle errors

  2. Leverage Context: Store error information in the context object for diagnostics

  3. Implement Recovery Patterns: Build error recovery using function composition

  4. Apply Resilience Patterns: Implement retry, circuit breakers, and fallbacks as needed

  5. Decentralized Recovery: Let nodes make local decisions about error handling

Last updated