Class: RubyReactor::Failure
- Inherits:
-
Object
- Object
- RubyReactor::Failure
- Defined in:
- lib/ruby_reactor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
readonly
Returns the value of attribute backtrace.
-
#code_snippet ⇒ Object
readonly
Returns the value of attribute code_snippet.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#exception_class ⇒ Object
readonly
Returns the value of attribute exception_class.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#reactor_name ⇒ Object
readonly
Returns the value of attribute reactor_name.
-
#retryable ⇒ Object
readonly
Returns the value of attribute retryable.
-
#step_arguments ⇒ Object
readonly
Returns the value of attribute step_arguments.
-
#step_name ⇒ Object
readonly
Returns the value of attribute step_name.
-
#validation_errors ⇒ Object
readonly
Returns the value of attribute validation_errors.
Instance Method Summary collapse
- #failure? ⇒ Boolean
-
#initialize(error, retryable: nil, step_name: nil, inputs: {}, backtrace: nil, redact_inputs: [], reactor_name: nil, step_arguments: {}, exception_class: nil, file_path: nil, line_number: nil, code_snippet: nil, invalid_payload: false, validation_errors: nil) ⇒ Failure
constructor
rubocop:disable Metrics/ParameterLists, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
- #invalid_payload? ⇒ Boolean
- #message ⇒ Object
- #retryable? ⇒ Boolean
- #skipped? ⇒ Boolean
- #success? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(error, retryable: nil, step_name: nil, inputs: {}, backtrace: nil, redact_inputs: [], reactor_name: nil, step_arguments: {}, exception_class: nil, file_path: nil, line_number: nil, code_snippet: nil, invalid_payload: false, validation_errors: nil) ⇒ Failure
rubocop:disable Metrics/ParameterLists, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/ruby_reactor.rb', line 92 def initialize(error, retryable: nil, step_name: nil, inputs: {}, backtrace: nil, redact_inputs: [], reactor_name: nil, step_arguments: {}, exception_class: nil, file_path: nil, line_number: nil, code_snippet: nil, invalid_payload: false, validation_errors: nil) # rubocop:enable Metrics/ParameterLists, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity @error = error # Handle case where error is a serialized hash (e.g. from async failure propagation) if @error.is_a?(Hash) attributes = extract_attributes_from_hash(@error) @error = attributes[:error] retryable = attributes[:retryable] if retryable.nil? step_name ||= attributes[:step_name] reactor_name ||= attributes[:reactor_name] inputs = attributes[:inputs] if inputs.empty? step_arguments = attributes[:step_arguments] if step_arguments.empty? raw_backtrace ||= attributes[:backtrace] || backtrace exception_class ||= attributes[:exception_class] file_path ||= attributes[:file_path] line_number ||= attributes[:line_number] code_snippet ||= attributes[:code_snippet] validation_errors ||= attributes[:validation_errors] end @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 raw_backtrace ||= backtrace || (@error.respond_to?(:backtrace) ? @error.backtrace : caller) @backtrace = filter_backtrace(raw_backtrace) @redact_inputs = redact_inputs @exception_class = exception_class || (@error.is_a?(Exception) ? @error.class.name : nil) @file_path = file_path @line_number = line_number @code_snippet = code_snippet @invalid_payload = invalid_payload @validation_errors = validation_errors end |
Instance Attribute Details
#backtrace ⇒ Object (readonly)
Returns the value of attribute backtrace.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def backtrace @backtrace end |
#code_snippet ⇒ Object (readonly)
Returns the value of attribute code_snippet.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def code_snippet @code_snippet end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def error @error end |
#exception_class ⇒ Object (readonly)
Returns the value of attribute exception_class.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def exception_class @exception_class end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def file_path @file_path end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def inputs @inputs end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def line_number @line_number end |
#reactor_name ⇒ Object (readonly)
Returns the value of attribute reactor_name.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def reactor_name @reactor_name end |
#retryable ⇒ Object (readonly)
Returns the value of attribute retryable.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def retryable @retryable end |
#step_arguments ⇒ Object (readonly)
Returns the value of attribute step_arguments.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def step_arguments @step_arguments end |
#step_name ⇒ Object (readonly)
Returns the value of attribute step_name.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def step_name @step_name end |
#validation_errors ⇒ Object (readonly)
Returns the value of attribute validation_errors.
88 89 90 |
# File 'lib/ruby_reactor.rb', line 88 def validation_errors @validation_errors end |
Instance Method Details
#failure? ⇒ Boolean
139 140 141 |
# File 'lib/ruby_reactor.rb', line 139 def failure? true end |
#invalid_payload? ⇒ Boolean
151 152 153 |
# File 'lib/ruby_reactor.rb', line 151 def invalid_payload? @invalid_payload end |
#message ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/ruby_reactor.rb', line 155 def msg = [build_header] msg << "Location: #{file_path}:#{line_number}" if file_path && line_number append_code_snippet(msg) append_inputs(msg) append_step_arguments(msg) append_backtrace(msg) msg.join("\n") end |
#retryable? ⇒ Boolean
143 144 145 |
# File 'lib/ruby_reactor.rb', line 143 def retryable? @retryable end |
#skipped? ⇒ Boolean
147 148 149 |
# File 'lib/ruby_reactor.rb', line 147 def skipped? false end |
#success? ⇒ Boolean
135 136 137 |
# File 'lib/ruby_reactor.rb', line 135 def success? false end |
#to_h ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ruby_reactor.rb', line 171 def to_h { success: false, error: , step_name: @step_name, inputs: @inputs, redact_inputs: @redact_inputs, reactor_name: @reactor_name, step_arguments: @step_arguments, exception_class: @exception_class, file_path: @file_path, line_number: @line_number, code_snippet: @code_snippet, validation_errors: @validation_errors, backtrace: @backtrace } end |
#to_s ⇒ Object
167 168 169 |
# File 'lib/ruby_reactor.rb', line 167 def to_s end |