class Chef::Formatters::ErrorDescription

Formatters::ErrorDescription

Class for displaying errors on STDOUT.

Attributes

sections[R]

Public Class Methods

new(title) click to toggle source
# File lib/chef/formatters/error_description.rb, line 30
def initialize(title)
  @title = title
  @sections = []
end

Public Instance Methods

display(out) click to toggle source
# File lib/chef/formatters/error_description.rb, line 39
def display(out)
  out.puts "=" * 80
  out.puts @title, :red
  out.puts "=" * 80
  out.puts "\n"

  sections.each do |section|
    section.each do |heading, text|
      display_section(heading, text, out)
    end
  end
  display_section("System Info:", error_context_info, out)
end
for_json() click to toggle source
# File lib/chef/formatters/error_description.rb, line 53
def for_json
  {
    "title" => @title,
    "sections" => @sections,
  }
end
section(heading, text) click to toggle source
# File lib/chef/formatters/error_description.rb, line 35
def section(heading, text)
  @sections << { heading => (text || "") }
end

Private Instance Methods

display_section(heading, text, out) click to toggle source
# File lib/chef/formatters/error_description.rb, line 62
def display_section(heading, text, out)
  out.puts heading
  out.puts "-" * heading.size
  out.puts text
  out.puts "\n"
end
error_context_info() click to toggle source
# File lib/chef/formatters/error_description.rb, line 69
def error_context_info
  context_info = { chef_version: Chef::VERSION }
  if Chef.node
    context_info[:platform] = Chef.node["platform"]
    context_info[:platform_version] = Chef.node["platform_version"]
  end
  # A string like "ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]"
  context_info[:ruby] = RUBY_DESCRIPTION
  # The argv[0] value.
  context_info[:program_name] = $PROGRAM_NAME
  # This is kind of wonky but it's the only way to get the entry path script.
  context_info[:executable] = File.realpath(caller.last[/^(.*):\d+:in /, 1])
  context_info.map { |k, v| "#{k}=#{v}" }.join("\n")
end