module Kitchen::Error

def self.formatted_backtrace(exception)

def self.formatted_backtrace(exception)
  if exception.backtrace.nil?
    []
  else
    [
      "Backtrace".center(22, "-"),
      exception.backtrace,
      "End Backtrace".center(22, "-"),
    ]
  end
end

def self.formatted_exception(exception, title = "Exception")

Returns:
  • (Array) - a formatted message

Parameters:
  • title (String) -- a custom title for the message
  • exception (::StandardError) -- an exception
def self.formatted_exception(exception, title = "Exception")
  [
    title.center(22, "-"),
    "Class: #{exception.class}",
    "Message: #{exception.message}",
    "".center(22, "-"),
  ]
end

def self.formatted_trace(exception, title = "Exception")

Returns:
  • (Array) - a formatted message

Parameters:
  • exception (::StandardError) -- an exception
def self.formatted_trace(exception, title = "Exception")
  arr = formatted_exception(exception, title).dup
  arr += formatted_backtrace(exception)
  if exception.respond_to?(:original) && exception.original
    arr += if exception.original.is_a? Array
             exception.original.map do |composite_exception|
               formatted_trace(composite_exception, "Composite Exception").flatten
             end
           else
             [
               formatted_exception(exception.original, "Nested Exception"),
               formatted_backtrace(exception),
             ].flatten
           end
  end
  arr.flatten
end

def self.warn_on_stderr(lines)

@params lines [Array] Array of lines that needs to be printed

kitchen diagnose.
output when parsing the output from the commands like
This will help to distinguish between the errors and
Log a warn message on STDERR device.
def self.warn_on_stderr(lines)
  Array(lines).each do |line|
    line = Color.colorize(line, :blue) if Kitchen.tty?
    $stderr.puts(line)
  end
end