Class: Toys::CLI::DefaultErrorHandler
- Inherits:
-
Object
- Object
- Toys::CLI::DefaultErrorHandler
- Defined in:
- lib/toys/cli.rb
Overview
A basic error handler that prints out captured errors to a stream or a logger.
Instance Method Summary collapse
-
#call(error) ⇒ Integer
The error handler routine.
-
#initialize(output: $stderr) ⇒ DefaultErrorHandler
constructor
Create an error handler.
Constructor Details
#initialize(output: $stderr) ⇒ DefaultErrorHandler
Create an error handler.
538 539 540 541 |
# File 'lib/toys/cli.rb', line 538 def initialize(output: $stderr) require "toys/utils/terminal" @terminal = Utils::Terminal.new(output: output) end |
Instance Method Details
#call(error) ⇒ Integer
The error handler routine. Prints out the error message and backtrace, and returns the correct result code.
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/toys/cli.rb', line 550 def call(error) cause = error case error when ContextualError cause = error.cause @terminal.puts(cause_string(cause)) @terminal.puts(context_string(error), :bold) when ::Interrupt @terminal.puts @terminal.puts("INTERRUPTED", :bold) else @terminal.puts(cause_string(error)) end exit_code_for(cause) end |