Skip to content

Errors Module

Exception hierarchy and error handling.


Exception Hierarchy

FlowEngineError (base)
├── ConfigurationError      # Invalid configuration
├── FlowExecutionError      # Runtime execution errors
│   ├── FlowTimeoutError    # Timeout exceeded
│   └── DeadlineCheckError  # Component didn't check deadline
├── ComponentError          # Component processing error
└── ConditionEvaluationError # Invalid/unsafe condition

FlowEngineError

Base exception for all FlowEngine errors.

FlowEngineError

FlowEngineError(message: str)

Bases: Exception

Base exception for all FlowEngine errors.

message instance-attribute

message = message

ConfigurationError

Raised for configuration validation errors.

ConfigurationError

ConfigurationError(message: str, config_path: Optional[str] = None, details: Optional[list[str]] = None)

Bases: FlowEngineError

Error in flow configuration.

Raised when there are issues with YAML parsing, schema validation, or invalid configuration values.

Attributes:

Name Type Description
config_path

Path to the configuration file (if applicable)

details

List of specific validation errors

config_path instance-attribute

config_path = config_path

details instance-attribute

details = details or []

FlowExecutionError

Raised for runtime execution errors.

FlowExecutionError

FlowExecutionError(message: str, flow_id: Optional[str] = None, step: Optional[str] = None)

Bases: FlowEngineError

Error during flow execution.

Raised when the flow execution fails for reasons other than component-specific errors.

Attributes:

Name Type Description
flow_id

Unique identifier of the flow execution

step

Name of the step where error occurred

flow_id instance-attribute

flow_id = flow_id

step instance-attribute

step = step

FlowTimeoutError

Raised when execution exceeds the configured timeout.

FlowTimeoutError

FlowTimeoutError(message: str, timeout: Optional[float], elapsed: float, flow_id: Optional[str] = None, step: Optional[str] = None)

Bases: FlowExecutionError

Error when flow execution exceeds timeout.

Raised when the total flow execution time exceeds the configured timeout_seconds value, or when a component's check_deadline() call detects the deadline has passed.

Attributes:

Name Type Description
timeout

The configured timeout in seconds (None if from deadline check)

elapsed

How much time had elapsed when timeout occurred

timeout instance-attribute

timeout = timeout

elapsed instance-attribute

elapsed = elapsed

DeadlineCheckError

Raised when a component fails to call check_deadline().

DeadlineCheckError

DeadlineCheckError(message: str, component: str, duration: float, threshold: float, flow_id: Optional[str] = None)

Bases: FlowExecutionError

Error when component fails to check deadline.

Raised when require_deadline_check is True and a long-running component does not call check_deadline() during execution. This enforces the cooperative timeout contract.

Attributes:

Name Type Description
component

Name of the non-compliant component

duration

How long the component took to execute

threshold

The threshold above which deadline checks are required

component instance-attribute

component = component

duration instance-attribute

duration = duration

threshold instance-attribute

threshold = threshold

ComponentError

Raised when a component fails during processing.

ComponentError

ComponentError(component: str, message: str, original_error: Optional[Exception] = None)

Bases: FlowEngineError

Error from a component.

Raised when a component fails during its lifecycle methods.

Attributes:

Name Type Description
component

Name of the component that failed

original_error

The underlying exception (if any)

component instance-attribute

component = component

original_error instance-attribute

original_error = original_error

ConditionEvaluationError

Raised for invalid or unsafe condition expressions.

ConditionEvaluationError

ConditionEvaluationError(message: str, condition: Optional[str] = None)

Bases: FlowEngineError

Error evaluating a condition expression.

Raised when a condition expression is invalid, unsafe, or fails during evaluation.

Attributes:

Name Type Description
condition

The condition expression string

condition instance-attribute

condition = condition

Usage Examples

Catching Specific Errors

from flowengine import (
    FlowEngine,
    ConfigLoader,
    ConfigurationError,
    FlowTimeoutError,
    DeadlineCheckError,
    ComponentError,
    ConditionEvaluationError,
)

try:
    config = ConfigLoader.load("flow.yaml")
    engine = FlowEngine(config, components)
    result = engine.execute()

except ConfigurationError as e:
    print(f"Config error: {e.message}")
    print(f"File: {e.config_path}")
    for detail in e.details:
        print(f"  - {detail}")

except FlowTimeoutError as e:
    print(f"Timeout at step '{e.step}'")
    print(f"Elapsed: {e.elapsed:.2f}s")
    print(f"Limit: {e.timeout}s")

except DeadlineCheckError as e:
    print(f"Component '{e.component}' didn't check deadline")
    print(f"Ran for {e.duration:.2f}s")

except ComponentError as e:
    print(f"Component '{e.component}' failed")
    print(f"Error: {e.message}")
    if e.original_error:
        print(f"Cause: {e.original_error}")

except ConditionEvaluationError as e:
    print(f"Invalid condition: {e.condition}")
    print(f"Error: {e.message}")

Raising Custom Errors

from flowengine import ComponentError, BaseComponent, FlowContext

class MyComponent(BaseComponent):
    def process(self, context: FlowContext) -> FlowContext:
        try:
            result = self.risky_operation()
        except ValueError as e:
            raise ComponentError(
                f"Invalid value in {self.name}",
                component=self.name,
                original_error=e,
            )
        context.set("result", result)
        return context

Checking Error Attributes

try:
    result = engine.execute()
except FlowTimeoutError as e:
    # All attributes available
    print(f"Message: {e.message}")
    print(f"Flow ID: {e.flow_id}")
    print(f"Step: {e.step}")
    print(f"Timeout: {e.timeout}")
    print(f"Elapsed: {e.elapsed}")

    # Can re-raise with additional context
    raise RuntimeError(f"Flow timed out at {e.step}") from e

Error Recovery Pattern

from flowengine import FlowEngineError

def execute_with_retry(engine, max_retries=3):
    for attempt in range(max_retries):
        try:
            return engine.execute()
        except FlowTimeoutError:
            if attempt == max_retries - 1:
                raise
            print(f"Retry {attempt + 1}/{max_retries}")
        except FlowEngineError:
            # Don't retry other errors
            raise