Class: Qs::ErrorHandler

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

Constant Summary collapse

STANDARD_ERROR_CLASSES =

these are standard error classes that we rescue and run through any configured error procs; use the same standard error classes that dat-worker-pool rescues

DatWorkerPool::Worker::STANDARD_ERROR_CLASSES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, context_hash) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



15
16
17
18
19
# File 'lib/qs/error_handler.rb', line 15

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.



13
14
15
# File 'lib/qs/error_handler.rb', line 13

def context
  @context
end

#error_procsObject (readonly)

Returns the value of attribute error_procs.



13
14
15
# File 'lib/qs/error_handler.rb', line 13

def error_procs
  @error_procs
end

#exceptionObject (readonly)

Returns the value of attribute exception.



13
14
15
# File 'lib/qs/error_handler.rb', line 13

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.



26
27
28
29
30
31
32
33
34
# File 'lib/qs/error_handler.rb', line 26

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