Class: Bumbleworks::Process::ErrorRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/bumbleworks/process/error_record.rb

Instance Method Summary collapse

Constructor Details

#initialize(process_error) ⇒ ErrorRecord

The initializer takes a Ruote::ProcessError instance.



5
6
7
# File 'lib/bumbleworks/process/error_record.rb', line 5

def initialize(process_error)
  @process_error = process_error
end

Instance Method Details

#backtraceObject

Returns the original error’s backtrace.

The original backtrace will be returned in standard backtrace format: an array of strings with paths and line numbers.



29
30
31
# File 'lib/bumbleworks/process/error_record.rb', line 29

def backtrace
  @process_error.h['trace'].split(/\n/)
end

#error_class_nameObject

Be aware that this class may not exist in the current binding when you instantiate the ErrorRecord; if it does not, calling #reify will throw an exception.



21
22
23
# File 'lib/bumbleworks/process/error_record.rb', line 21

def error_class_name
  @process_error.h['class']
end

#feiObject

Returns the FlowExpressionId of the expression where this error occurred.



11
12
13
# File 'lib/bumbleworks/process/error_record.rb', line 11

def fei
  @process_error.fei
end

#messageObject

Returns the original error message.

Ruote’s error logging has a strange issue; the message recorded and returned via the Ruote::ProcessError instance is the full #inspect of the error. This method strips away the resulting cruft (if it exists) and leaves behind just the message itself.



39
40
41
42
# File 'lib/bumbleworks/process/error_record.rb', line 39

def message
  @message ||= @process_error.message.
    gsub(/\#\<#{error_class_name}: (.*)\>$/, '\1')
end

#reifyObject

Re-instantiates the original exception.

If you wish to re-create the actual exception that was raised during process execution, this method will attempt to return an instance of the error class, with the message and backtrace restored.

In order for this to work, the error class itself must be a defined constant in the current binding; if it’s not, you’ll get an exception. Be cognizant of this caveat if you choose to use this feature; Bumbleworks makes no attempt to protect you.

This is not because Bumbleworks doesn’t love you. It just wants you to spread your wings, and the only way to truly experience flight is to first taste the ground.



59
60
61
62
63
64
# File 'lib/bumbleworks/process/error_record.rb', line 59

def reify
  klass = Bumbleworks::Support.constantize(error_class_name)
  err = klass.new(message)
  err.set_backtrace(backtrace)
  err
end