Module: Kitchen::Error
- Included in:
- StandardError
- Defined in:
- lib/kitchen/errors.rb
Overview
All Kitchen errors and exceptions.
Class Method Summary collapse
-
.formatted_exception(exception, title = "Exception") ⇒ Array<String>
Creates an array of strings, representing a formatted exception that can be viewed by a human.
-
.formatted_trace(exception) ⇒ Array<String>
Creates an array of strings, representing a formatted exception, containing backtrace and nested exception info as necessary, that can be viewed by a human.
Class Method Details
.formatted_exception(exception, title = "Exception") ⇒ Array<String>
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
----------------------
72 73 74 75 76 77 78 79 |
# File 'lib/kitchen/errors.rb', line 72 def self.formatted_exception(exception, title = "Exception") [ title.center(22, "-"), "Class: #{exception.class}", "Message: #{exception.}", "".center(22, "-") ] end |
.formatted_trace(exception) ⇒ Array<String>
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
----------------------
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kitchen/errors.rb', line 46 def self.formatted_trace(exception) arr = formatted_exception(exception).dup last = arr.pop if exception.respond_to?(:original) && exception.original arr += formatted_exception(exception.original, "Nested Exception") last = arr.pop end arr += ["Backtrace".center(22, "-"), exception.backtrace, last].flatten arr end |