Error Handling#
Marcus error framework and recovery strategies.
Auto-generated from source code docstrings.
Error Framework#
Marcus Error Handling Framework.
Comprehensive error handling system designed for autonomous agent environments. Provides structured error types, rich context, and intelligent recovery strategies.
- class src.core.error_framework.ErrorSeverity[source]#
Bases:
EnumError severity levels for prioritization and alerting.
- LOW = 'low'#
- MEDIUM = 'medium'#
- HIGH = 'high'#
- CRITICAL = 'critical'#
- class src.core.error_framework.ErrorCategory[source]#
Bases:
EnumHigh-level error categories for monitoring and classification.
- TRANSIENT = 'transient'#
- CONFIGURATION = 'configuration'#
- BUSINESS_LOGIC = 'business_logic'#
- INTEGRATION = 'integration'#
- SECURITY = 'security'#
- SYSTEM = 'system'#
- class src.core.error_framework.ErrorContext[source]#
Bases:
objectRich context information for error debugging and recovery.
- __init__(operation='', operation_id=<factory>, agent_id=None, task_id=None, agent_state=None, timestamp=<factory>, correlation_id=<factory>, system_state=None, integration_name=None, integration_state=None, user_context=None, custom_context=None)#
- class src.core.error_framework.RemediationSuggestion[source]#
Bases:
objectActionable remediation suggestions for autonomous agents.
- __init__(immediate_action=None, long_term_solution=None, fallback_strategy=None, retry_strategy=None, escalation_path=None)#
- exception src.core.error_framework.MarcusBaseError[source]#
Bases:
ExceptionBase exception class for Marcus-specific errors.
Provides rich context, categorization, and remediation suggestions for autonomous agent error handling.
- __init__(message, error_code=None, context=None, remediation=None, severity=ErrorSeverity.MEDIUM, retryable=False, cause=None)[source]#
- Parameters:
message (str)
error_code (str | None)
context (ErrorContext | None)
remediation (RemediationSuggestion | Dict[str, Any] | None)
severity (ErrorSeverity)
retryable (bool)
cause (Exception | None)
- exception src.core.error_framework.TransientError[source]#
Bases:
MarcusBaseErrorBase class for transient errors that can be automatically retried.
- exception src.core.error_framework.NetworkTimeoutError[source]#
Bases:
TransientErrorNetwork operation timed out.
Bases:
TransientErrorExternal service is temporarily unavailable.
- exception src.core.error_framework.RateLimitError[source]#
Bases:
TransientErrorRate limit exceeded for API calls.
- exception src.core.error_framework.TemporaryResourceError[source]#
Bases:
TransientErrorTemporary resource unavailability (memory, disk, etc.).
- exception src.core.error_framework.ConfigurationError[source]#
Bases:
MarcusBaseErrorBase class for configuration-related errors.
- exception src.core.error_framework.MissingCredentialsError[source]#
Bases:
ConfigurationErrorRequired API credentials are missing.
- exception src.core.error_framework.InvalidConfigurationError[source]#
Bases:
ConfigurationErrorConfiguration values are invalid.
- exception src.core.error_framework.MissingDependencyError[source]#
Bases:
ConfigurationErrorRequired dependency is missing.
- exception src.core.error_framework.EnvironmentError[source]#
Bases:
ConfigurationErrorEnvironment setup is incorrect.
- exception src.core.error_framework.BusinessLogicError[source]#
Bases:
MarcusBaseErrorBase class for business logic violations.
- exception src.core.error_framework.TaskAssignmentError[source]#
Bases:
BusinessLogicErrorError in task assignment logic.
- exception src.core.error_framework.WorkflowViolationError[source]#
Bases:
BusinessLogicErrorWorkflow rule violation.
- exception src.core.error_framework.ValidationError[source]#
Bases:
BusinessLogicErrorData validation failed.
- exception src.core.error_framework.StateConflictError[source]#
Bases:
BusinessLogicErrorSystem state conflict detected.
- exception src.core.error_framework.TaskValidationError[source]#
Bases:
BusinessLogicErrorTask implementation validation failed.
- exception src.core.error_framework.ProjectRootNotFoundError[source]#
Bases:
ConfigurationErrorCannot determine project root directory.
- exception src.core.error_framework.IntegrationError[source]#
Bases:
MarcusBaseErrorBase class for external integration errors.
- exception src.core.error_framework.KanbanIntegrationError[source]#
Bases:
IntegrationErrorKanban board integration error.
- exception src.core.error_framework.AIProviderError[source]#
Bases:
IntegrationErrorAI provider integration error.
- exception src.core.error_framework.AuthenticationError[source]#
Bases:
IntegrationErrorAuthentication failed for external service.
- exception src.core.error_framework.ExternalServiceError[source]#
Bases:
IntegrationErrorGeneric external service error.
- exception src.core.error_framework.SecurityError[source]#
Bases:
MarcusBaseErrorBase class for security-related errors.
- exception src.core.error_framework.AuthorizationError[source]#
Bases:
SecurityErrorAuthorization failed - insufficient permissions.
- exception src.core.error_framework.WorkspaceSecurityError[source]#
Bases:
SecurityErrorWorkspace security violation.
- exception src.core.error_framework.PermissionError[source]#
Bases:
SecurityErrorPermission denied for operation.
- exception src.core.error_framework.SystemError[source]#
Bases:
MarcusBaseErrorBase class for critical system errors.
- exception src.core.error_framework.ResourceExhaustionError[source]#
Bases:
SystemErrorSystem resource exhaustion.
- exception src.core.error_framework.CorruptedStateError[source]#
Bases:
SystemErrorSystem state corruption detected.
- exception src.core.error_framework.DatabaseError[source]#
Bases:
SystemErrorDatabase operation failed.
- exception src.core.error_framework.CriticalDependencyError[source]#
Bases:
SystemErrorCritical system dependency failure.
- src.core.error_framework.error_context(operation, agent_id=None, task_id=None, integration_name=None, custom_context=None)[source]#
Context manager for automatic error context injection.
- Return type:
- Parameters:
- Usage:
- with error_context(“create_task”, agent_id=”agent_123”, task_id=”task_456”):
# operations that might raise Marcus errors pass
- class src.core.error_framework.ErrorResponseFormatter[source]#
Bases:
objectFormats error responses for different output formats (MCP, JSON, etc.).
- static format_for_mcp(error, include_debug=False)[source]#
Format error for MCP protocol response.
- Return type:
- Parameters:
error (MarcusBaseError)
include_debug (bool)
- static format_for_logging(error)[source]#
Format error for structured logging.
- Return type:
- Parameters:
error (MarcusBaseError)
- static format_user_friendly(error)[source]#
Format error for user-friendly display.
- Return type:
- Parameters:
error (MarcusBaseError)
- src.core.error_framework.MarcusError#
alias of
MarcusBaseError
Error Strategies#
Marcus Error Handling Strategies.
Advanced error handling patterns for autonomous agent environments: - Retry policies with exponential backoff - Circuit breaker pattern for external services - Fallback mechanisms for graceful degradation - Error aggregation for batch operations
Status#
AVAILABLE BUT NOT INTEGRATED into the MCP tool layer. These components
are tested in isolation but have zero imports from src/marcus_mcp/.
The simpler src/core/resilience.py decorators (@with_retry,
@with_fallback) are what production code currently uses.
This module is the recommended target for future integration when adding resilience to Kanban API calls, AI provider calls, or other external service boundaries in the MCP layer.
- class src.core.error_strategies.CircuitBreakerState[source]#
Bases:
EnumCircuit breaker states.
- CLOSED = 'closed'#
- OPEN = 'open'#
- HALF_OPEN = 'half_open'#
- class src.core.error_strategies.RetryPolicy[source]#
Bases:
EnumRetry policy types.
- NONE = 'none'#
- FIXED_DELAY = 'fixed_delay'#
- EXPONENTIAL_BACKOFF = 'exponential_backoff'#
- LINEAR_BACKOFF = 'linear_backoff'#
- JITTERED_EXPONENTIAL = 'jittered_exponential'#
- class src.core.error_strategies.RetryConfig[source]#
Bases:
objectConfiguration for retry behavior.
- retry_on: tuple[type[Exception], ...] = (<class 'src.core.error_framework.TransientError'>, <class 'src.core.error_framework.IntegrationError'>)#
- __init__(max_attempts=3, base_delay=1.0, max_delay=60.0, multiplier=2.0, jitter=True, retry_on=(<class 'src.core.error_framework.TransientError'>, <class 'src.core.error_framework.IntegrationError'>), stop_on=())#
- class src.core.error_strategies.CircuitBreakerConfig[source]#
Bases:
objectConfiguration for circuit breaker behavior.
- class src.core.error_strategies.CircuitBreakerStatus[source]#
Bases:
objectCurrent status of a circuit breaker.
- state: CircuitBreakerState = 'closed'#
- __init__(state=CircuitBreakerState.CLOSED, failure_count=0, success_count=0, last_failure_time=None, next_attempt_time=None, failure_history=<factory>)#
- class src.core.error_strategies.CircuitBreaker[source]#
Bases:
objectCircuit breaker implementation for external service calls.
Prevents cascading failures by temporarily blocking calls to failing services.
- __init__(name, config=None)[source]#
- Parameters:
name (str)
config (CircuitBreakerConfig | None)
- property lock: Lock#
Get circuit breaker lock, creating it if needed in the current event loop.
- class src.core.error_strategies.RetryHandler[source]#
Bases:
objectAdvanced retry handler with multiple backoff strategies.
Supports exponential backoff, jitter, and configurable retry policies.
- __init__(config=None)[source]#
- Parameters:
config (RetryConfig | None)
- class src.core.error_strategies.FallbackHandler[source]#
Bases:
objectHandles fallback strategies for graceful degradation.
Provides multiple fallback options when primary operations fail.
- class src.core.error_strategies.ErrorAggregator[source]#
Bases:
objectAggregates errors from batch operations.
Collects multiple errors and provides summary reporting.
- errors: List[MarcusBaseError]#
- src.core.error_strategies.with_circuit_breaker(name, config=None)[source]#
Add circuit breaker protection to functions.
- class src.core.error_strategies.ErrorStrategyRegistry[source]#
Bases:
objectRegistry for managing error handling strategies across the application.
- circuit_breakers: Dict[str, CircuitBreaker]#
- fallback_handlers: Dict[str, FallbackHandler]#
- retry_configs: Dict[str, RetryConfig]#
- get_circuit_breaker(name, config=None)[source]#
Get or create a circuit breaker for a service.
- Return type:
- Parameters:
name (str)
config (CircuitBreakerConfig | None)
- get_fallback_handler(name)[source]#
Get or create a fallback handler.
- Return type:
- Parameters:
name (str)
- register_retry_config(operation, config)[source]#
Register a retry configuration for an operation.
- Return type:
- Parameters:
operation (str)
config (RetryConfig)
Error Responses#
Marcus Error Response System.
Standardized error response formatting for different contexts: - MCP protocol responses - JSON API responses - User-friendly messages - Logging formats - Monitoring/alerting formats
- class src.core.error_responses.ResponseFormat[source]#
Bases:
EnumSupported response formats.
- MCP = 'mcp'#
- JSON_API = 'json_api'#
- USER_FRIENDLY = 'user_friendly'#
- LOGGING = 'logging'#
- MONITORING = 'monitoring'#
- DEBUG = 'debug'#
- class src.core.error_responses.ErrorResponseConfig[source]#
Bases:
objectConfiguration for error response formatting.
- __init__(include_debug_info=False, include_stack_trace=False, include_system_context=False, include_remediation=True, max_message_length=500, sanitize_sensitive_data=True, custom_fields=<factory>)#
- class src.core.error_responses.ErrorResponseFormatter[source]#
Bases:
objectComprehensive error response formatter for Marcus errors.
Provides standardized formatting across different contexts while maintaining security and usability.
- __init__(config=None)[source]#
- Parameters:
config (ErrorResponseConfig | None)
- format_error(error, format_type, additional_context=None)[source]#
Format error for specified response type.
- Parameters:
error (
Union[MarcusBaseError,Exception]) – The error to format.format_type (
ResponseFormat) – Target format for the response.additional_context (
Optional[Dict[str,Any]]) – Additional context to include.
- Return type:
- Returns:
Formatted error response dictionary
- class src.core.error_responses.BatchErrorResponseFormatter[source]#
Bases:
objectFormats responses for batch operations with multiple errors.
Provides summary views and detailed breakdowns of batch operation results.
- __init__(formatter=None)[source]#
- Parameters:
formatter (ErrorResponseFormatter | None)
- format_batch_response(operation_name, errors, successes, total_operations, format_type=ResponseFormat.JSON_API)[source]#
Format response for batch operation with multiple errors.
- Return type:
- Parameters:
operation_name (str)
errors (List[MarcusBaseError])
successes (int)
total_operations (int)
format_type (ResponseFormat)
- src.core.error_responses.create_success_response(data=None, message='Operation completed successfully', metadata=None)[source]#
Create a standardized success response.
- src.core.error_responses.create_error_response(error, format_type=ResponseFormat.MCP, config=None, additional_context=None)[source]#
Create a standardized error response.
- Return type:
- Parameters:
error (MarcusBaseError | Exception)
format_type (ResponseFormat)
config (ErrorResponseConfig | None)