Module: Dbwatcher::Storage::Concerns::ErrorHandler
- Included in:
- BaseStorage
- Defined in:
- lib/dbwatcher/storage/concerns/error_handler.rb
Overview
Provides standardized error handling capabilities for storage classes
This concern can be included in storage classes to provide consistent error handling patterns, logging, and recovery mechanisms.
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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dbwatcher/storage/concerns/error_handler.rb', line 28 def safe_operation(operation_name, default_value = nil, &block) block.call rescue JSON::ParserError => e log_error_with_exception("JSON parsing failed in #{operation_name}", e) default_value rescue Errno::ENOENT => e log_error_with_exception("File not found in #{operation_name}", e) default_value rescue Errno::EACCES => e log_error_with_exception("Permission denied in #{operation_name}", e) raise StorageError, "Permission denied: #{e.}" rescue StandardError => e log_error_with_exception("#{operation_name} failed", e) default_value end |
#with_error_handling(operation) { ... } ⇒ Object
Executes a block with error handling that raises StorageError on failure
50 51 52 53 54 55 56 |
# File 'lib/dbwatcher/storage/concerns/error_handler.rb', line 50 def with_error_handling(operation, &block) block.call rescue StandardError => e = "Storage #{operation} failed: #{e.}" log_error_with_exception(, e) raise StorageError, end |