Class: Bumbleworks::Process::ErrorRecord

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process_error) ⇒ ErrorRecord

The initializer takes a Ruote::ProcessError instance.



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

def initialize(process_error)
  @process_error = process_error
end

Instance Attribute Details

#process_errorObject (readonly)

Returns the value of attribute process_error.



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

def 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.



45
46
47
# File 'lib/bumbleworks/process/error_record.rb', line 45

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.



37
38
39
# File 'lib/bumbleworks/process/error_record.rb', line 37

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

#expressionObject

Returns the expression where this error occurred.



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

def expression
  Bumbleworks::Expression.from_fei(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.



55
56
57
58
# File 'lib/bumbleworks/process/error_record.rb', line 55

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

#processObject

Returns the process in which this error occurred.



27
28
29
# File 'lib/bumbleworks/process/error_record.rb', line 27

def process
  Bumbleworks::Process.new(wfid)
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.



75
76
77
78
79
80
# File 'lib/bumbleworks/process/error_record.rb', line 75

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

#replayObject

Replays the error’s process at the point where the error occurred. Should only be called when the cause of the error has been fixed, since otherwise this will just cause the error to show up again.



17
18
19
# File 'lib/bumbleworks/process/error_record.rb', line 17

def replay
  Bumbleworks.dashboard.replay_at_error(@process_error)
end