Class: Dynflow::ExecutionPlan::Steps::Error

Inherits:
Serializable show all
Extended by:
Algebrick::Matching
Includes:
Algebrick::TypeCheck
Defined in:
lib/dynflow/execution_plan/steps/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Serializable

constantize, from_hash

Constructor Details

#initialize(exception_class, message, backtrace, exception) ⇒ Error

Returns a new instance of Error.



26
27
28
29
30
31
# File 'lib/dynflow/execution_plan/steps/error.rb', line 26

def initialize(exception_class, message, backtrace, exception)
  @exception_class = Child! exception_class, Exception
  @message         = Type! message, String
  @backtrace       = Type! backtrace, Array
  @exception       = Type! exception, Exception, NilClass
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



7
8
9
# File 'lib/dynflow/execution_plan/steps/error.rb', line 7

def backtrace
  @backtrace
end

#exception_classObject (readonly)

Returns the value of attribute exception_class.



7
8
9
# File 'lib/dynflow/execution_plan/steps/error.rb', line 7

def exception_class
  @exception_class
end

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/dynflow/execution_plan/steps/error.rb', line 7

def message
  @message
end

Class Method Details

.new(*args) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dynflow/execution_plan/steps/error.rb', line 9

def self.new(*args)
  case args.size
  when 1
    match obj = args.first,
          (on String do
            super(StandardError, obj, caller, nil)
          end),
          (on Exception do
            super(obj.class, obj.message, obj.backtrace, obj)
          end)
  when 3, 4
    super(*args.values_at(0..3))
  else
    raise ArgumentError, "wrong number of arguments #{args}"
  end
end

.new_from_hash(hash) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/dynflow/execution_plan/steps/error.rb', line 33

def self.new_from_hash(hash)
  exception_class = begin
                      hash[:exception_class].constantize
                    rescue NameError
                      Errors::UnknownError.for_exception_class(hash[:exception_class])
                    end
  self.new(exception_class, hash[:message], hash[:backtrace], nil)
end

Instance Method Details

#exceptionObject



56
57
58
59
# File 'lib/dynflow/execution_plan/steps/error.rb', line 56

def exception
  @exception ||
      exception_class.exception(message).tap { |e| e.set_backtrace backtrace }
end

#to_hashObject



42
43
44
45
46
47
# File 'lib/dynflow/execution_plan/steps/error.rb', line 42

def to_hash
  recursive_to_hash class:           self.class.name,
                    exception_class: exception_class.to_s,
                    message:         message,
                    backtrace:       backtrace
end

#to_sObject



49
50
51
52
53
54
# File 'lib/dynflow/execution_plan/steps/error.rb', line 49

def to_s
  format '%s (%s)\n%s',
         (@exception || self).message,
         (@exception ? @exception.class : exception_class),
         (@exception || self).backtrace
end