Class: Jekyll::L10n::ErrorHandler
- Inherits:
-
Object
- Object
- Jekyll::L10n::ErrorHandler
- Defined in:
- lib/jekyll-l10n/utils/error_handler.rb
Overview
Handles errors with graceful fallback and logging.
ErrorHandler provides error handling utilities for gracefully managing exceptions, logging them with context, and providing default fallback values. This keeps the build process running even when individual operations fail.
Key responsibilities:
-
Execute code with error catching
-
Log errors with context information
-
Provide fallback default values on error
-
Optional debug backtraces
Class Method Summary collapse
-
.handle_with_default(context, default_value) { ... } ⇒ Object
Execute code with error catching and fallback value.
-
.handle_with_logging(context) { ... } ⇒ Object?
Execute code with error catching and fallback logging.
-
.log_error(context, error) ⇒ void
Log an error with context.
Class Method Details
.handle_with_default(context, default_value) { ... } ⇒ Object
Execute code with error catching and fallback value.
Executes the provided block and catches any StandardError, logging it with context and returning the default value.
47 48 49 50 51 52 |
# File 'lib/jekyll-l10n/utils/error_handler.rb', line 47 def self.handle_with_default(context, default_value) yield rescue StandardError => e log_error(context, e) default_value end |
.handle_with_logging(context) { ... } ⇒ Object?
Execute code with error catching and fallback logging.
Executes the provided block and catches any StandardError, logging it with context and returning nil.
31 32 33 34 35 36 |
# File 'lib/jekyll-l10n/utils/error_handler.rb', line 31 def self.handle_with_logging(context) yield rescue StandardError => e log_error(context, e) nil end |
.log_error(context, error) ⇒ void
This method returns an undefined value.
Log an error with context.
Logs error message and optionally backtrace if DEBUG environment variable is set.
61 62 63 64 |
# File 'lib/jekyll-l10n/utils/error_handler.rb', line 61 def self.log_error(context, error) Jekyll.logger.error 'Localization', "Error in #{context}: #{error.}" Jekyll.logger.debug 'Localization', error.backtrace.join("\n") if ENV['DEBUG'] end |