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

Constant Summary

Constants inherited from Serializable

Serializable::LEGACY_TIME_FORMAT, Serializable::TIME_FORMAT

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.



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

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.



9
10
11
# File 'lib/dynflow/execution_plan/steps/error.rb', line 9

def backtrace
  @backtrace
end

#exception_classObject (readonly)

Returns the value of attribute exception_class.



9
10
11
# File 'lib/dynflow/execution_plan/steps/error.rb', line 9

def exception_class
  @exception_class
end

#messageObject (readonly)

Returns the value of attribute message.



9
10
11
# File 'lib/dynflow/execution_plan/steps/error.rb', line 9

def message
  @message
end

Class Method Details

.new(*args) ⇒ Object



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

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



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

def self.new_from_hash(hash)
  exception_class = begin
                      Utils.constantize(hash[:exception_class])
                    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



58
59
60
61
# File 'lib/dynflow/execution_plan/steps/error.rb', line 58

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

#to_hashObject



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

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

#to_sObject



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

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