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