class Arcanus::ErrorHandler
Central location of all logic for how exceptions are presented to the user.
Attributes
ui[R]
Public Class Methods
new(ui)
click to toggle source
Creates exception handler that can display output to user via the given user interface.
@param [Arcanus::UI] user interface to print output to
# File lib/arcanus/error_handler.rb, line 8 def initialize(ui) @ui = ui end
Public Instance Methods
handle(ex)
click to toggle source
Display appropriate output to the user for the given exception, returning a semantic exit status code.
@return [Integer] exit status code
# File lib/arcanus/error_handler.rb, line 16 def handle(ex) case ex when Errors::CommandFailedError, Errors::DecryptionError ui.error ex.message CLI::ExitCodes::ERROR when Errors::UsageError ui.error ex.message CLI::ExitCodes::USAGE when Errors::ConfigurationError ui.error ex.message CLI::ExitCodes::CONFIG else print_unexpected_exception(ex) CLI::ExitCodes::SOFTWARE end end
Private Instance Methods
print_unexpected_exception(ex)
click to toggle source
# File lib/arcanus/error_handler.rb, line 38 def print_unexpected_exception(ex) ui.bold_error ex.message ui.error ex.backtrace.join("\n") ui.warning 'Report this bug at ', newline: false ui.info BUG_REPORT_URL ui.newline ui.info 'To help fix this issue, please include:' ui.print '- The above stack trace' ui.print '- Ruby version: ', newline: false ui.info RUBY_VERSION end