Class: Toys::CLI::DefaultErrorHandler

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(output = $stderr) ⇒ DefaultErrorHandler

Create an error handler.

Parameters:

  • output (IO) (defaults to: $stderr)

    Where to write errors. Default is $stderr.



284
285
286
# File 'lib/toys/cli.rb', line 284

def initialize(output = $stderr)
  @terminal = Utils::Terminal.new(output: output)
end

Instance Method Details

#call(error) ⇒ Object

The error handler routine. Prints out the error message and backtrace.

Parameters:

  • error (Exception)

    The error that occurred.



293
294
295
296
297
# File 'lib/toys/cli.rb', line 293

def call(error)
  @terminal.puts(cause_string(error.cause))
  @terminal.puts(context_string(error), :bold)
  -1
end