class Terraspace::Terraform::RemoteState::Marker::PrettyTracer
Public Class Methods
new(caller_line)
click to toggle source
# File lib/terraspace/terraform/remote_state/marker/pretty_tracer.rb, line 3 def initialize(caller_line) @caller_line = caller_line end
Public Instance Methods
pretty_trace(path, error_line_number)
click to toggle source
# File lib/terraspace/terraform/remote_state/marker/pretty_tracer.rb, line 14 def pretty_trace(path, error_line_number) io = StringIO.new context = 5 # lines of context top, bottom = [error_line_number-context-1, 0].max, error_line_number+context-1 io.puts "Here's the line in #{Terraspace::Util.pretty_path(path)} with the error:\n\n" lines = IO.read(path).split("\n") context = 5 # lines of context top, bottom = [error_line_number-context-1, 0].max, error_line_number+context-1 spacing = lines.size.to_s.size lines[top..bottom].each_with_index do |line_content, index| line_number = top+index+1 if line_number == error_line_number io.printf("%#{spacing}d %s\n".color(:red), line_number, line_content) else io.printf("%#{spacing}d %s\n", line_number, line_content) end end io.string end
source_code()
click to toggle source
/full/path/to/app/stacks/a1/tfvars/dev.tfvars:4:in `__tilt_5560'
# File lib/terraspace/terraform/remote_state/marker/pretty_tracer.rb, line 8 def source_code line = @caller_line.sub(/:in `.*/,'') path, error_line_number = line.split(':') pretty_trace(path, error_line_number.to_i) end