Class: Qs::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/qs/error_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, context_hash) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



9
10
11
12
13
# File 'lib/qs/error_handler.rb', line 9

def initialize(exception, context_hash)
  @exception   = exception
  @context     = ErrorContext.new(context_hash)
  @error_procs = context_hash[:daemon_data].error_procs.reverse
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/qs/error_handler.rb', line 7

def context
  @context
end

#error_procsObject (readonly)

Returns the value of attribute error_procs.



7
8
9
# File 'lib/qs/error_handler.rb', line 7

def error_procs
  @error_procs
end

#exceptionObject (readonly)

Returns the value of attribute exception.



7
8
9
# File 'lib/qs/error_handler.rb', line 7

def exception
  @exception
end

Instance Method Details

#runObject

The exception that we are handling can change in the case that the configured error proc raises an exception. If this occurs, the new exception will be passed to subsequent error procs. This is designed to avoid “hidden” errors, this way the daemon will log based on the last exception that occurred.



20
21
22
23
24
25
26
27
28
# File 'lib/qs/error_handler.rb', line 20

def run
  @error_procs.each do |error_proc|
    begin
      error_proc.call(@exception, @context)
    rescue StandardError => proc_exception
      @exception = proc_exception
    end
  end
end