module Kitchen::Error
All Kitchen
errors and exceptions.
@author Fletcher Nichol <fnichol@nichol.ca>
Public Class Methods
formatted_backtrace(exception)
click to toggle source
# File lib/kitchen/errors.rb, line 62 def self.formatted_backtrace(exception) if exception.backtrace.nil? [] else [ "Backtrace".center(22, "-"), exception.backtrace, "End Backtrace".center(22, "-"), ] end end
formatted_exception(exception, title = "Exception")
click to toggle source
Creates an array of strings, representing a formatted exception that can be viewed by a human. Thanks to MiniTest for the inspiration upon which this output has been designed.
For example:
------Exception------- Class: Kitchen::StandardError Message: I have failed you ----------------------
@param exception [::StandardError] an exception @param title [String] a custom title for the message
(default: `"Exception"`)
@return [Array<String>] a formatted message
# File lib/kitchen/errors.rb, line 89 def self.formatted_exception(exception, title = "Exception") [ title.center(22, "-"), "Class: #{exception.class}", "Message: #{exception.message}", "".center(22, "-"), ] end
formatted_trace(exception, title = "Exception")
click to toggle source
Creates an array of strings, representing a formatted exception, containing backtrace and nested exception info as necessary, that can be viewed by a human.
For example:
------Exception------- Class: Kitchen::StandardError Message: Failure starting the party ---Nested Exception--- Class: IOError Message: not enough directories for a party ------Backtrace------- nil ----------------------
@param exception [::StandardError] an exception @return [Array<String>] a formatted message
# File lib/kitchen/errors.rb, line 43 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