"""Create fallback_executor
Generated by Phi-Octopus Eden
2025-11-07 03:16:47.175682
"""

```python
from typing import Callable, Any


class FallbackExecutor:
    """
    A class for executing a primary function and providing fallbacks in case of errors.
    
    This executor wraps around a given callable (the main execution logic) and attempts to run it.
    If an exception occurs during the execution of the main function, one or more fallback functions
    are executed in order until either no further fallbacks remain or one succeeds without raising.
    
    Parameters:
        primary_function (Callable): The primary function to be executed.
        fallbacks (list[Callable]): A list of fallback functions that will be tried if the primary fails.
        error_types (tuple[type], optional): A tuple of exception types to catch. If not provided, all exceptions are caught.

    Usage:
        def main_function(x: int) -> str:
            return f"Processed {x}"

        def fallback1(x: int) -> str:
            return "Fallback 1 processed"

        def fallback2(x: int) -> str:
            return "Fallback 2 processed"
        
        executor = FallbackExecutor(main_function, [fallback1, fallback2], (ValueError,))
        
        result = executor.execute(10)
        print(result)
    """

    def __init__(self, primary_function: Callable[[Any], Any], fallbacks: list[Callable[[Any], Any]], error_types: tuple[type] = None):
        self.primary_function = primary_function
        self.fallbacks = fallbacks
        self.error_types = error_types if error_types else (Exception,)
    
    def execute(self, *args, **kwargs) -> Any:
        """
        Execute the primary function with provided arguments. If it raises an exception,
        try each fallback in order until one succeeds or no more are available.
        
        :param args: Arguments to pass to the functions
        :param kwargs: Keyword arguments to pass to the functions
        :return: The result of the last executed function (either primary or a fallback)
        """
        try:
            return self.primary_function(*args, **kwargs)
        except self.error_types as e:
            for fallback in self.fallbacks:
                try:
                    return fallback(*args, **kwargs)
                except self.error_types:
                    continue
            raise


# Example usage
def main_function(x: int) -> str:
    if x < 0:
        raise ValueError("Negative numbers are not allowed")
    return f"Processed {x}"

def fallback1(x: int) -> str:
    print(f"Falling back to {fallback1.__name__}")
    return "Fallback 1 processed"

def fallback2(x: int) -> str:
    print(f"Falling back to {fallback2.__name__}")
    return "Fallback 2 processed"

executor = FallbackExecutor(main_function, [fallback1, fallback2], (ValueError,))
result = executor.execute(-5)
print(result)

# Should execute main_function and raise ValueError
try:
    result = executor.execute(-10)
except Exception as e:
    print(f"Caught error: {e}")
    
# Should try fallback1, then fallback2
result = executor.execute(30)
print(result)
```