Parent

Class/Module Index [+]

Quicksearch

Ruote::ErrorHandler

A ruote service for turning exceptions into process errors (or letting those error fire any potential :on_error attributes in the process definition).

This service is used, by the worker, the dispatch pool and some receivers (like the one in ruote-beanstalk).

Public Class Methods

new(context) click to toggle source
# File lib/ruote/error_handler.rb, line 38
def initialize (context)

  @context = context
end

Public Instance Methods

action_handle(action, fei, exception) click to toggle source

As used by some receivers (see ruote-beanstalk's receiver).

# File lib/ruote/error_handler.rb, line 56
def action_handle (action, fei, exception)

  fexp = Ruote::Exp::FlowExpression.fetch(@context, fei)

  msg = {
    'action' => action,
    'fei' => fei,
    'participant_name' => fexp.h.participant_name,
    'workitem' => fexp.h.applied_workitem }

  handle(msg, fexp, exception)
end
msg_handle(msg, exception) click to toggle source

As used by the dispatch pool and the worker.

# File lib/ruote/error_handler.rb, line 45
def msg_handle (msg, exception)

  fexp = Ruote::Exp::FlowExpression.fetch(
    @context, msg['fei'] || msg['workitem']['fei']
  ) rescue nil

  handle(msg, fexp, exception)
end

Protected Instance Methods

handle(msg, fexp, exception) click to toggle source

As used by the worker.

# File lib/ruote/error_handler.rb, line 73
def handle (msg, fexp, exception)

  wfid = msg['wfid'] || (msg['fei']['wfid'] rescue nil)
  fei = msg['fei'] || (fexp.h.fei rescue nil)

  backtrace = exception.backtrace || []

  # debug only

  if $DEBUG || ARGV.include?('-d')

    puts "\n== worker intercepted error =="
    puts
    p exception
    puts backtrace[0, 20].join("\n")
    puts "..."
    puts
    puts "-- msg --"
    msg.keys.sort.each { |k|
      puts "    #{k.inspect} =>\n#{msg[k].inspect}"
    }
    puts "-- . --"
    puts
  end

  # on_error ?

  return if fexp && fexp.handle_on_error(msg, exception)

  # emit 'msg'

  @context.storage.put_msg(
    'error_intercepted',
    'error_class' => exception.class.name,
    'error_message' => exception.message,
    'error_backtrace' => exception.backtrace,
    # for backward compatibility
    'message' => exception.inspect,
    'wfid' => wfid,
    'msg' => msg)

  # fill error in the error journal

  @context.storage.put(
    'type' => 'errors',
    '_id' => "err_#{Ruote.to_storage_id(fei)}",
    'message' => exception.inspect,
    'trace' => backtrace.join("\n"),
    'fei' => fei,
    'msg' => msg
  ) if fei
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.