Module: Leetcoder::Helpers::ErrorHandler

Included in:
Cli
Defined in:
lib/leetcoder/leetcoder/helpers/error_handler.rb

Instance Method Summary collapse

Instance Method Details

#error_handlerObject

wrap code block with error_hanlder do; end to rescue errors



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/leetcoder/leetcoder/helpers/error_handler.rb', line 7

def error_handler
  yield
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
  puts "error: #{e}"
  puts help_toast
rescue Errors::EmptyCommand
  puts "Hi there! Please provide a valid command! #{help_toast} "
rescue Errors::InvalidCommand
  puts "Invalid Command! #{help_toast}"
rescue StandardError => e
  puts "error: #{e}"
  puts e.backtrace
end

#help_toastObject



21
22
23
# File 'lib/leetcoder/leetcoder/helpers/error_handler.rb', line 21

def help_toast
  "\nRun `leetcoder --help` to see available commands."
end