improve error handling #223
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Type
Description of Change
This PR introduces a comprehensive custom exception class hierarchy to improve error handling, classification, and debugging across the MCPMark codebase.
Key Changes:
New Exception System (
src/exceptions.py)MCPMarkExceptionas the base exception class with support for:MissingConfigurationError,InvalidConfigurationError,ModelConfigurationErrorMCPServiceError,MCPServiceTimeoutError,MCPServiceAuthenticationError,StateManagerError,TaskManagerErrorAgentExecutionError,AgentTimeoutError,LLMRateLimitError,LLMQuotaExceededError,LLMContextWindowExceededErrorTaskExecutionError,TaskSetupError,TaskCleanupErrorEnhanced Error Handling (
src/errors.py)is_retryable_error()to support both string errors and exception objectsstandardize_error_message()to work with new exception classesextract_error_message()utility functionconvert_to_mcpmark_exception()for backward compatibility and gradual migrationCore Module Updates
ValueErrorwithInvalidConfigurationErrorfor agent validationimport_class()usingConfigurationErrorValueErrorwithInvalidConfigurationErrorfor service validationValueErrorwithMissingConfigurationErrorandInvalidConfigurationErrorValueErrorwithModelConfigurationErrorAgent Module Updates
LLMRateLimitError,LLMQuotaExceededError,LLMContextWindowExceededError)AgentTimeoutErrorTask Manager Updates
TaskVerificationErrorfor better verification error handlingBenefits:
retryableflag enables smarter retry decisionsis_retryable_error()andstandardize_error_message()support both old and new formatsconvert_to_mcpmark_exception()allows incremental adoptionFiles Changed:
src/exceptions.py(320+ lines)src/errors.pysrc/evaluator.pysrc/factory.pysrc/services.pysrc/config/config_schema.pysrc/model_config.pysrc/agents/base_agent.pysrc/agents/mcpmark_agent.pysrc/base/task_manager.pyTesting:
Additional Information
Migration Notes:
ValueError,RuntimeError, etc. will continue to work.MCPMarkExceptionclass.convert_to_mcpmark_exception()to wrap standard exceptions.Future Improvements:
mcp_services/) can be gradually migrated to use the new exception classesRelated Issues:
This PR addresses the need for better error handling and classification as identified in the project's error handling enhancement requirements.