Module: Dbwatcher::Storage::ErrorHandler
- Defined in:
- lib/dbwatcher/storage/errors.rb
Overview
Provides error handling capabilities for storage operations
This module can be included in storage classes to provide standardized error handling and logging capabilities.
Instance Method Summary collapse
-
#safe_operation(operation_name, default_value = nil) { ... } ⇒ Object
Executes a block with error handling and optional default return value.
-
#with_error_handling(operation) { ... } ⇒ Object
Executes a block with error handling that raises StorageError on failure.
Instance Method Details
#safe_operation(operation_name, default_value = nil) { ... } ⇒ Object
Executes a block with error handling and optional default return value
51 52 53 54 55 56 57 58 59 |
# File 'lib/dbwatcher/storage/errors.rb', line 51 def safe_operation(operation_name, default_value = nil, &block) block.call rescue JSON::ParserError => e log_error("JSON parsing failed in #{operation_name}", e) default_value rescue StandardError => e log_error("#{operation_name} failed", e) default_value end |
#with_error_handling(operation) { ... } ⇒ Object
Executes a block with error handling that raises StorageError on failure
67 68 69 70 71 72 |
# File 'lib/dbwatcher/storage/errors.rb', line 67 def with_error_handling(operation, &block) block.call rescue StandardError => e warn "Storage #{operation} failed: #{e.}" raise StorageError, "#{operation} failed: #{e.}" end |