Class: RubyReactor::Failure

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

Direct Known Subclasses

MaxRetriesExhaustedFailure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, retryable: nil, step_name: nil, inputs: {}, backtrace: nil, redact_inputs: [], reactor_name: nil, step_arguments: {}) ⇒ Failure

rubocop:disable Metrics/ParameterLists



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ruby_reactor.rb', line 44

def initialize(error, retryable: nil, step_name: nil, inputs: {}, backtrace: nil, redact_inputs: [],
               reactor_name: nil, step_arguments: {})
  # rubocop:enable Metrics/ParameterLists
  @error = error
  @retryable = if retryable.nil?
                 error.respond_to?(:retryable?) ? error.retryable? : true
               else
                 retryable
               end
  @step_name = step_name
  @reactor_name = reactor_name
  @inputs = inputs
  @step_arguments = step_arguments
  @backtrace = backtrace || (error.respond_to?(:backtrace) ? error.backtrace : caller)
  @redact_inputs = redact_inputs
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



41
42
43
# File 'lib/ruby_reactor.rb', line 41

def backtrace
  @backtrace
end

#errorObject (readonly)

Returns the value of attribute error.



41
42
43
# File 'lib/ruby_reactor.rb', line 41

def error
  @error
end

#inputsObject (readonly)

Returns the value of attribute inputs.



41
42
43
# File 'lib/ruby_reactor.rb', line 41

def inputs
  @inputs
end

#reactor_nameObject (readonly)

Returns the value of attribute reactor_name.



41
42
43
# File 'lib/ruby_reactor.rb', line 41

def reactor_name
  @reactor_name
end

#retryableObject (readonly)

Returns the value of attribute retryable.



41
42
43
# File 'lib/ruby_reactor.rb', line 41

def retryable
  @retryable
end

#step_argumentsObject (readonly)

Returns the value of attribute step_arguments.



41
42
43
# File 'lib/ruby_reactor.rb', line 41

def step_arguments
  @step_arguments
end

#step_nameObject (readonly)

Returns the value of attribute step_name.



41
42
43
# File 'lib/ruby_reactor.rb', line 41

def step_name
  @step_name
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ruby_reactor.rb', line 65

def failure?
  true
end

#messageObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ruby_reactor.rb', line 73

def message
  msg = []
  header = "Error"
  header += " in reactor '#{reactor_name}'" if reactor_name
  header += " step '#{step_name}'" if step_name
  header += ": #{error_message}"

  msg << header

  if inputs && !inputs.empty?
    msg << "Inputs:"
    inputs.each do |key, value|
      val = @redact_inputs.include?(key) ? "[REDACTED]" : value.inspect
      msg << "  #{key}: #{val}"
    end
  end

  if step_arguments && !step_arguments.empty?
    msg << "Step Arguments:"
    step_arguments.each do |key, value|
      # We might want to redact step arguments too if they come from redacted inputs
      # For now, let's assume if the input key matches a redacted input key, it should be redacted
      # But step arguments have different names.
      # We can't easily track redaction for step arguments without more metadata.
      # For now, let's just display them.
      msg << "  #{key}: #{value.inspect}"
    end
  end

  if backtrace
    msg << "Backtrace:"
    msg << backtrace.take(5).map { |line| "  #{line}" }.join("\n")
  end

  msg.join("\n")
end

#retryable?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/ruby_reactor.rb', line 69

def retryable?
  @retryable
end

#success?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ruby_reactor.rb', line 61

def success?
  false
end

#to_sObject



110
111
112
# File 'lib/ruby_reactor.rb', line 110

def to_s
  message
end