Module: Leetcoder::Helpers::ErrorHandler
- Included in:
- Cli
- Defined in:
- lib/leetcoder/leetcoder/helpers/error_handler.rb
Instance Method Summary collapse
-
#error_handler ⇒ Object
wrap code block with error_hanlder do; end to rescue errors.
- #help_toast ⇒ Object
Instance Method Details
#error_handler ⇒ Object
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_toast ⇒ Object
21 22 23 |
# File 'lib/leetcoder/leetcoder/helpers/error_handler.rb', line 21 def help_toast "\nRun `leetcoder --help` to see available commands." end |