Exceptions API π¨
FlowyML defines a structured exception hierarchy so you can catch errors at the right level of granularity. All custom exceptions inherit from a common base class, making it easy to write broad except clauses for framework errors while still allowing fine-grained handling of specific failure modes such as missing artifacts, invalid configurations, or orchestrator timeouts.
Custom exceptions thrown by flowyml.
Error Handling Module
Error handling utilities for robust pipeline execution.
Classes
CircuitBreaker(failure_threshold: int = 5, timeout: float = 60, recovery_timeout: float = 300, expected_exceptions: list[type[Exception]] | None = None)
Circuit breaker pattern implementation.
Prevents cascading failures by failing fast when a service is down.
Example
Initialize circuit breaker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
failure_threshold
|
int
|
Number of failures before opening circuit |
5
|
timeout
|
float
|
Seconds to wait before trying again |
60
|
recovery_timeout
|
float
|
Seconds to wait before fully closing circuit |
300
|
expected_exceptions
|
list[type[Exception]] | None
|
Exceptions that trigger the breaker |
None
|
Source code in flowyml/core/error_handling.py
Functions
call(func: Callable, *args, **kwargs) -> Any
Call function with circuit breaker protection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Function to call |
required |
*args
|
Positional arguments |
()
|
|
**kwargs
|
Keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Function result |
Raises:
| Type | Description |
|---|---|
CircuitOpenError
|
If circuit is open |
Source code in flowyml/core/error_handling.py
reset() -> None
CircuitBreakerConfig(failure_threshold: int = 5, timeout: float = 60, recovery_timeout: float = 300, expected_exceptions: list[type[Exception]] = (lambda: [Exception])())
dataclass
Configuration for circuit breaker.
Attributes
expected_exceptions: list[type[Exception]] = field(default_factory=(lambda: [Exception]))
class-attribute
instance-attribute
Exceptions that trigger circuit breaker
failure_threshold: int = 5
class-attribute
instance-attribute
Number of failures before opening circuit
recovery_timeout: float = 300
class-attribute
instance-attribute
Time to wait before fully closing circuit (seconds)
timeout: float = 60
class-attribute
instance-attribute
Time to wait before trying again (seconds)
CircuitOpenError
Bases: Exception
Exception raised when circuit breaker is open.
CircuitState
Bases: Enum
Circuit breaker states.
ExponentialBackoff(initial: float = 1.0, max_delay: float = 60.0, multiplier: float = 2.0, jitter: bool = True)
Exponential backoff retry strategy.
Example
Initialize exponential backoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial
|
float
|
Initial delay in seconds |
1.0
|
max_delay
|
float
|
Maximum delay in seconds |
60.0
|
multiplier
|
float
|
Backoff multiplier |
2.0
|
jitter
|
bool
|
Add random jitter to delays |
True
|
Source code in flowyml/core/error_handling.py
Functions
get_delay() -> float
Get delay for current attempt.
Returns:
| Type | Description |
|---|---|
float
|
Delay in seconds |
Source code in flowyml/core/error_handling.py
FallbackConfig(fallback_func: Callable, fallback_on: list[type[Exception]] = (lambda: [Exception])(), max_fallback_attempts: int = 1)
dataclass
Configuration for fallback handler.
Attributes
fallback_func: Callable
instance-attribute
Fallback function to call on error
fallback_on: list[type[Exception]] = field(default_factory=(lambda: [Exception]))
class-attribute
instance-attribute
Exceptions that trigger fallback
max_fallback_attempts: int = 1
class-attribute
instance-attribute
Maximum number of fallback attempts
FallbackHandler(fallback_func: Callable, fallback_on: list[type[Exception]] | None = None, max_attempts: int = 1)
Fallback handler for graceful degradation.
Example
Initialize fallback handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fallback_func
|
Callable
|
Function to call as fallback |
required |
fallback_on
|
list[type[Exception]] | None
|
Exceptions that trigger fallback |
None
|
max_attempts
|
int
|
Maximum fallback attempts |
1
|
Source code in flowyml/core/error_handling.py
Functions
call(func: Callable, *args, **kwargs) -> Any
Call function with fallback protection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Primary function to call |
required |
*args
|
Positional arguments |
()
|
|
**kwargs
|
Keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Function result or fallback result |
Source code in flowyml/core/error_handling.py
OnFailureConfig(action: str = 'log', recipients: list[str] = list(), include_logs: bool = True, include_traceback: bool = True)
dataclass
Configuration for failure handling.
Attributes
action: str = 'log'
class-attribute
instance-attribute
Action to take (log, email, slack, webhook)
include_logs: bool = True
class-attribute
instance-attribute
Include logs in notification
include_traceback: bool = True
class-attribute
instance-attribute
Include full traceback
recipients: list[str] = field(default_factory=list)
class-attribute
instance-attribute
Recipients for notifications
RetryConfig(max_attempts: int = 3, backoff: ExponentialBackoff | None = None, retry_on: list[type[Exception]] = (lambda: [Exception])(), not_retry_on: list[type[Exception]] = list())
dataclass
Configuration for retry logic.
Attributes
backoff: ExponentialBackoff | None = None
class-attribute
instance-attribute
Backoff strategy
max_attempts: int = 3
class-attribute
instance-attribute
Maximum number of retry attempts
not_retry_on: list[type[Exception]] = field(default_factory=list)
class-attribute
instance-attribute
Exceptions NOT to retry on
retry_on: list[type[Exception]] = field(default_factory=(lambda: [Exception]))
class-attribute
instance-attribute
Exceptions to retry on
Functions
execute_with_retry(func: Callable, retry_config: RetryConfig, *args, **kwargs: Any) -> Any
Execute function with retry logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Function to execute |
required |
retry_config
|
RetryConfig
|
Retry configuration |
required |
*args
|
Positional arguments |
()
|
|
**kwargs
|
Any
|
Keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Function result |
Source code in flowyml/core/error_handling.py
on_failure(action: str = 'log', recipients: list[str] | None = None, include_logs: bool = True, include_traceback: bool = True) -> OnFailureConfig
Create failure handling configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Action to take on failure |
'log'
|
recipients
|
list[str] | None
|
Recipients for notifications |
None
|
include_logs
|
bool
|
Include logs in notification |
True
|
include_traceback
|
bool
|
Include full traceback |
True
|
Returns:
| Type | Description |
|---|---|
OnFailureConfig
|
OnFailureConfig instance |
Source code in flowyml/core/error_handling.py
retry(max_attempts: int = 3, backoff: ExponentialBackoff | None = None, on: list[type[Exception]] | None = None, not_on: list[type[Exception]] | None = None) -> RetryConfig
Create retry configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_attempts
|
int
|
Maximum retry attempts |
3
|
backoff
|
ExponentialBackoff | None
|
Backoff strategy |
None
|
on
|
list[type[Exception]] | None
|
Exceptions to retry on |
None
|
not_on
|
list[type[Exception]] | None
|
Exceptions not to retry on |
None
|
Returns:
| Type | Description |
|---|---|
RetryConfig
|
RetryConfig instance |
Source code in flowyml/core/error_handling.py
See Also
- Error Handling Guide β best practices for catching and recovering from errors in pipelines