Class: DeepTest::MarshallableExceptionWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/marshallable_exception_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ MarshallableExceptionWrapper

Returns a new instance of MarshallableExceptionWrapper.



5
6
7
8
9
# File 'lib/deep_test/marshallable_exception_wrapper.rb', line 5

def initialize(exception)
  @classname = exception.class.name
  @message = exception.message
  @backtrace = exception.backtrace
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



3
4
5
# File 'lib/deep_test/marshallable_exception_wrapper.rb', line 3

def backtrace
  @backtrace
end

#classnameObject (readonly)

Returns the value of attribute classname.



3
4
5
# File 'lib/deep_test/marshallable_exception_wrapper.rb', line 3

def classname
  @classname
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/deep_test/marshallable_exception_wrapper.rb', line 3

def message
  @message
end

Instance Method Details

#==(other) ⇒ Object



11
12
13
14
15
# File 'lib/deep_test/marshallable_exception_wrapper.rb', line 11

def ==(other)
  classname == other.classname &&
    message == other.message &&
  backtrace == other.backtrace
end

#resolveObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/deep_test/marshallable_exception_wrapper.rb', line 17

def resolve
  begin
    klass = eval("::" + classname) 
    resolved_message = message
  rescue => e
    DeepTest.logger.debug("Unable to load exception class: #{classname}: #{e.message}")
    DeepTest.logger.debug(e.backtrace.join("\n"))

    klass = UnloadableException
    resolved_message = "#{classname}: #{message}"
  end

  begin
    resolved_exception = klass.new resolved_message
  rescue => e
    DeepTest.logger.debug("Unable to instantiation exception class: #{classname}: #{e.message}")
    DeepTest.logger.debug(e.backtrace.join("\n"))

    resolved_exception = UnloadableException.new resolved_message
  end

  resolved_exception.set_backtrace backtrace
  resolved_exception
end