Class: Hobo::ErrorHandlers::Friendly
- Inherits:
-
Object
- Object
- Hobo::ErrorHandlers::Friendly
- Includes:
- ExitCodeMap
- Defined in:
- lib/hobo/error_handlers/friendly.rb
Constant Summary
Constants included from ExitCodeMap
ExitCodeMap::DEFAULT_EXIT_CODE, ExitCodeMap::EXIT_CODES
Instance Method Summary collapse
Instance Method Details
#handle(error) ⇒ Object
6 7 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hobo/error_handlers/friendly.rb', line 6 def handle error require 'tmpdir' log_file = File.join(Dir.tmpdir, 'hobo_error.log') # Not possible to match Interrupt class unless we use class name as string for some reason! case error.class.to_s when "Interrupt" Hobo.ui.warning "\n\nCaught Interrupt. Aborting\n" when "Hobo::ExternalCommandError" FileUtils.cp error.output.path, log_file File.open(log_file, "a") do |file| file.write "\n(#{error.class}) #{error.}\n\n#{error.backtrace.join("\n")}" end Hobo.ui.error <<-ERROR The following external command appears to have failed (exit status #{error.exit_code}): #{error.command} The output of the command has been logged to #{log_file} ERROR when "Hobo::InvalidCommandOrOpt" Hobo.ui.error "\n#{error.}" Hobo.ui.info error.cli.help_formatter.help if error.cli when "Hobo::MissingArgumentsError" Hobo.ui.error "\n#{error.}" Hobo.ui.info error.cli.help_formatter.help(target: error.command) if error.cli when "Hobo::UserError" Hobo.ui.error "\n#{error.}\n" when "Hobo::ProjectOnlyError" Hobo.ui.error "\nHobo requires you to be in a project directory for this command!\n" when "Hobo::HostCheckError" Hobo.ui.error "\nHobo has detected a problem with your system configuration:\n" Hobo.ui.warning error.advice.gsub(/^/, ' ') when "Hobo::Error" Hobo.ui.error "\n#{error.}\n" else File.write(log_file, "(#{error.class}) #{error.}\n\n#{error.backtrace.join("\n")}") Hobo.ui.error <<-ERROR An unexpected error has occured: #{error.} The backtrace has been logged to #{log_file} ERROR end return EXIT_CODES[error.class.to_s] || DEFAULT_EXIT_CODE end |