Class: Arcanus::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/arcanus/error_handler.rb

Overview

Central location of all logic for how exceptions are presented to the user.

Instance Method Summary collapse

Constructor Details

#initialize(ui) ⇒ ErrorHandler

Creates exception handler that can display output to user via the given user interface.

Parameters:


8
9
10
# File 'lib/arcanus/error_handler.rb', line 8

def initialize(ui)
  @ui = ui
end

Instance Method Details

#handle(ex) ⇒ Integer

Display appropriate output to the user for the given exception, returning a semantic exit status code.

Returns:

  • (Integer)

    exit status code


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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