Class: Gerrit::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/gerrit/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:

  • user (Gerrit::UI)

    interface to print output to



8
9
10
# File 'lib/gerrit/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
# File 'lib/gerrit/error_handler.rb', line 16

def handle(ex)
  case ex
  when Errors::UsageError
    ui.error ex.message
    CLI::ExitCodes::USAGE
  when Errors::ConfigurationError
    ui.error ex.message
    CLI::ExitCodes::CONFIG
  when Errors::GerritCommandFailedError
    ui.error ex.message
    CLI::ExitCodes::ERROR
  else
    print_unexpected_exception(ex)
    CLI::ExitCodes::SOFTWARE
  end
end