Coverage for src/dataknobs_fsm/core/exceptions.py: 56%
45 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-20 16:46 -0600
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-20 16:46 -0600
1"""FSM Core Exceptions Module.
3This module defines core exception types used throughout the FSM system.
4"""
6from typing import Any, Dict
9class FSMError(Exception):
10 """Base exception for all FSM-related errors."""
12 def __init__(self, message: str, details: Dict[str, Any] | None = None):
13 super().__init__(message)
14 self.details = details or {}
17class InvalidConfigurationError(FSMError):
18 """Raised when FSM configuration is invalid."""
19 pass
22class StateExecutionError(FSMError):
23 """Raised when state execution fails."""
25 def __init__(self, state_name: str, message: str, details: Dict[str, Any] | None = None):
26 super().__init__(f"State '{state_name}' execution failed: {message}", details)
27 self.state_name = state_name
30class TransitionError(FSMError):
31 """Raised when state transition fails."""
33 def __init__(self, from_state: str, to_state: str, message: str, details: Dict[str, Any] | None = None):
34 super().__init__(f"Transition from '{from_state}' to '{to_state}' failed: {message}", details)
35 self.from_state = from_state
36 self.to_state = to_state
39class ResourceError(FSMError):
40 """Raised when resource operations fail."""
42 def __init__(self, resource_id: str, message: str, details: Dict[str, Any] | None = None):
43 super().__init__(f"Resource '{resource_id}' error: {message}", details)
44 self.resource_id = resource_id
47class ValidationError(FSMError):
48 """Raised when data validation fails."""
49 pass
52class FunctionError(FSMError):
53 """Raised when a function execution fails.
55 This represents deterministic failures in user-defined functions
56 (transforms, validators, conditions) that should not be retried.
57 These are code errors, not transient failures.
58 """
60 def __init__(self,
61 message: str,
62 function_name: str | None = None,
63 from_state: str | None = None,
64 to_state: str | None = None,
65 details: Dict[str, Any] | None = None):
66 if function_name:
67 message = f"Function '{function_name}' failed: {message}"
68 super().__init__(message, details)
69 self.function_name = function_name
70 self.from_state = from_state
71 self.to_state = to_state
74class TimeoutError(FSMError):
75 """Raised when operation times out."""
76 pass
79class ConcurrencyError(FSMError):
80 """Raised when concurrent execution fails."""
81 pass
84class CircuitBreakerError(FSMError):
85 """Raised when circuit breaker is open."""
87 def __init__(self, wait_time: float | None = None, details: Dict[str, Any] | None = None):
88 if wait_time:
89 message = f"Circuit breaker is open (wait {wait_time:.1f}s)"
90 else:
91 message = "Circuit breaker is open"
92 super().__init__(message, details)
93 self.wait_time = wait_time
96class ETLError(FSMError):
97 """Raised when ETL operations fail."""
98 pass
101class BulkheadTimeoutError(FSMError):
102 """Raised when bulkhead queue times out."""
103 pass