Class: SharedTools::Tools::ErrorHandlingTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::ErrorHandlingTool
- Defined in:
- lib/shared_tools/tools/error_handling_tool.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(operation:, simulate_error: nil, max_retries: 3, **data) ⇒ Hash
Execute operation with comprehensive error handling.
-
#initialize(logger: nil) ⇒ ErrorHandlingTool
constructor
A new instance of ErrorHandlingTool.
Constructor Details
#initialize(logger: nil) ⇒ ErrorHandlingTool
Returns a new instance of ErrorHandlingTool.
93 94 95 96 97 |
# File 'lib/shared_tools/tools/error_handling_tool.rb', line 93 def initialize(logger: nil) @logger = logger || RubyLLM.logger @resources_allocated = [] @operation_start_time = nil end |
Class Method Details
.name ⇒ Object
25 |
# File 'lib/shared_tools/tools/error_handling_tool.rb', line 25 def self.name = 'error_handling_tool' |
Instance Method Details
#execute(operation:, simulate_error: nil, max_retries: 3, **data) ⇒ Hash
Execute operation with comprehensive error handling
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/shared_tools/tools/error_handling_tool.rb', line 107 def execute(operation:, simulate_error: nil, max_retries: 3, **data) @operation_start_time = Time.now @logger.info("ErrorHandlingTool#execute operation=#{operation} simulate_error=#{simulate_error}") begin # Validate inputs validate_preconditions(operation, data, max_retries) # Allocate resources (demonstration) allocate_resources # Perform main operation result = perform_operation(operation, data, simulate_error, max_retries) # Validate outputs validate_postconditions(result) @logger.info("Operation completed successfully") { success: true, result: result, metadata: } rescue ValidationError => e @logger.error("Validation error: #{e.message}") handle_validation_error(e, operation) rescue NetworkError => e @logger.error("Network error: #{e.message}") handle_network_error(e, operation) rescue AuthorizationError => e @logger.error("Authorization error: #{e.message}") (e, operation) rescue ResourceNotFoundError => e @logger.error("Resource not found: #{e.message}") handle_resource_not_found_error(e, operation) rescue StandardError => e @logger.error("General error: #{e.class} - #{e.message}") handle_general_error(e, operation) ensure cleanup_resources end end |