Module: MuxTf::ErrorHandlingMethods
- Included in:
- InitFormatter, PlanFormatter, StderrLineHandler
- Defined in:
- lib/mux_tf/error_handling_methods.rb
Instance Method Summary collapse
- #handle_error_states(meta, state, line) ⇒ Object
- #log_unhandled_line(state, line, reason: nil) ⇒ Object
- #print_errors(meta) ⇒ Object
- #setup_error_handling(parser, from_states:) ⇒ Object
Instance Method Details
#handle_error_states(meta, state, line) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mux_tf/error_handling_methods.rb', line 13 def handle_error_states(, state, line) case state when :error_block if [:init_error] # turn this into an error first [:errors] ||= [] [:errors] << { type: :error, message: [:init_error].join("\n") # body: meta[:init_error] } .delete(:init_error) end [:current_error] = { type: :unknown, body: [] } when :error_block_error, :error_block_warning clean_line = pastel.strip(line).gsub(/^│ /, "") if clean_line =~ /^(Warning|Error): (.+)$/ [:current_error][:type] = $LAST_MATCH_INFO[1].downcase.to_sym [:current_error][:message] = $LAST_MATCH_INFO[2] elsif clean_line == "" # skip double empty lines [:current_error][:body] << clean_line if [:current_error][:body].last != "" else [:current_error][:body] ||= [] [:current_error][:body] << clean_line end when :after_error case pastel.strip(line) when "╵" # closing of an error block if [:current_error][:type] == :error [:errors] ||= [] [:errors] << [:current_error] end if [:current_error][:type] == :warning [:warnings] ||= [] [:warnings] << [:current_error] end .delete(:current_error) end when :init_error [:init_error] ||= [] [:init_error] << line else return false end true end |
#log_unhandled_line(state, line, reason: nil) ⇒ Object
64 65 66 |
# File 'lib/mux_tf/error_handling_methods.rb', line 64 def log_unhandled_line(state, line, reason: nil) p [state, pastel.strip(line), reason] end |
#print_errors(meta) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mux_tf/error_handling_methods.rb', line 68 def print_errors() [:errors]&.each do |error| log "-" * 20 log pastel.red("Error: #{error[:message]}") error[:body]&.each do |line| log pastel.red(line), depth: 1 end log "" end end |
#setup_error_handling(parser, from_states:) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/mux_tf/error_handling_methods.rb', line 5 def setup_error_handling(parser, from_states:) parser.state(:init_error, /^Terraform encountered problems during initialisation/, [:none]) parser.state(:error_block, /^╷/, from_states | [:after_error, :init_error]) parser.state(:error_block_error, /^│ Error: /, [:error_block, :init_error]) parser.state(:error_block_warning, /^│ Warning: /, [:error_block, :init_error]) parser.state(:after_error, /^╵/, [:error_block, :error_block_error, :error_block_warning, :init_error]) end |