Parent

Class/Module Index [+]

Quicksearch

HammerCLI::ExceptionHandler

Public Class Methods

new(options={}) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 7
def initialize(options={})
  @logger = Logging.logger['Exception']
  @output = options[:output]
end

Public Instance Methods

handle_exception(e, options={}) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 23
def handle_exception(e, options={})
  @options = options
  handler = mappings.reverse.find { |m| e.class.respond_to?(:"<=") ? e.class <= m[0] : false }
  return send(handler[1], e) if handler
  raise e
end
mappings() click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 12
def mappings
  [
    [Exception, :handle_general_exception], # catch all
    [Clamp::HelpWanted, :handle_help_wanted],
    [Clamp::UsageError, :handle_usage_exception],
    [RestClient::ResourceNotFound, :handle_not_found],
    [RestClient::Unauthorized, :handle_unauthorized],
    [ApipieBindings::DocLoadingError, :handle_apipie_docloading_error],
  ]
end
output() click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 30
def output
  @output || HammerCLI::Output::Output.new
end

Protected Instance Methods

handle_apipie_docloading_error(e) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 88
def handle_apipie_docloading_error(e)
  rake_command = "rake apipie:cache"
  print_error _("Could not load API description from the server\n"           "  - is your server down?\n"           "  - was \"#{rake_command}\" run on the server when using apipie cache? (typical production settings))\n")
  log_full_error e
  HammerCLI::EX_CONFIG
end
handle_general_exception(e) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 59
def handle_general_exception(e)
  print_error _("Error: %s") % e.message
  log_full_error e
  HammerCLI::EX_SOFTWARE
end
handle_help_wanted(e) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 71
def handle_help_wanted(e)
  print_message e.command.help
  HammerCLI::EX_OK
end
handle_not_found(e) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 76
def handle_not_found(e)
  print_error e.message
  log_full_error e
  HammerCLI::EX_NOT_FOUND
end
handle_unauthorized(e) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 82
def handle_unauthorized(e)
  print_error _("Invalid username or password")
  log_full_error e
  HammerCLI::EX_UNAUTHORIZED
end
handle_usage_exception(e) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 65
def handle_usage_exception(e)
  print_error _("Error: %{message}\n\nSee: '%{path} --help'") % {:message => e.message, :path => e.command.invocation_path}
  log_full_error e
  HammerCLI::EX_USAGE
end
log_full_error(e) click to toggle source
# File lib/hammer_cli/exception_handler.rb, line 51
def log_full_error(e)
  backtrace = e.backtrace || []
  error = "\n\n#{e.class} (#{e.message}):\n    " +
    backtrace.join("\n    ")
    "\n\n"
  @logger.error error
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.