Sha256: afe52316980a70fc0bcb57324b37d33f566ea3bc9b659bea3466d9c02760edad

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

module DeepTest
  class MarshallableExceptionWrapper
    attr_reader :classname, :message, :backtrace

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

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

    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
  end

  class UnloadableException < StandardError; end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
deep_test_pre-2.0 lib/deep_test/marshallable_exception_wrapper.rb
jstorimer-deep-test-2.0.0 lib/deep_test/marshallable_exception_wrapper.rb
jstorimer-deep-test-0.2.0 lib/deep_test/marshallable_exception_wrapper.rb
jstorimer-deep-test-0.1.0 lib/deep_test/marshallable_exception_wrapper.rb