Class: Morpheus::Cli::ErrorHandler

Inherits:
Object
  • Object
show all
Includes:
PrintHelper
Defined in:
lib/morpheus/cli/error_handler.rb

Instance Method Summary collapse

Methods included from PrintHelper

#generate_usage_bar, included, #print_available_options, #print_dry_run, #print_errors, #print_green_success, #print_red_alert, #print_rest_exception, #print_rest_exception_request_and_response, #print_rest_request, #print_rest_response, #print_results_pagination, #print_stats_usage, #print_yellow_warning, #required_blue_prompt

Instance Method Details

#handle_error(err, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/morpheus/cli/error_handler.rb', line 8

def handle_error(err, options={})
  # heh
  if Morpheus::Logging.debug? && options[:debug].nil?
    options[:debug] = true
  end
  case (err)
  when OptionParser::InvalidOption, OptionParser::AmbiguousOption, OptionParser::MissingArgument, OptionParser::InvalidArgument
    # raise err
    print_red_alert "#{err.message}"
    puts "Try -h for help with this command."
  when Errno::ECONNREFUSED
    print_red_alert "#{err.message}"
    # more special errors?
  when OpenSSL::SSL::SSLError
    print_red_alert "Error Communicating with the Appliance. #{err.message}"
  when RestClient::Exception
    print_rest_exception(err, options)
  else
    print_red_alert "Unexpected Error."
    if !options[:debug]
      print "Use --debug for more information.\n"
    end
  end

  if options[:debug]
    print Term::ANSIColor.red, "\n", "#{err.class}: #{err.message}", "\n", Term::ANSIColor.reset
    print err.backtrace.join("\n"), "\n\n"
  else
    #print "Use --debug for more information.\n"
  end
end