Sha256: 19cc08975835badf8364c631c3ee3ed581f4340bc73cc15a37a798a2f8e8eb9d
Contents?: true
Size: 922 Bytes
Versions: 4
Compression:
Stored size: 922 Bytes
Contents
module Todoloo class ErrorHandler def initialize(kind) @handler = new_handler_proc(kind) end def call(error, original_exception: nil) # TODO(errors): Handle `original_exception` @handler.call(error) end private def new_handler_proc(kind) case kind when :raise proc { |e| raise e } when :stderr, :log, :trace new_handler($stderr) when String File.open(kind, "w") else if kind.respond_to?(:write) proc do |e| if e.is_a?(Error) kind.puts(e.message) kind.puts(e.backtrace) if e.backtrace && !e.backtrace.empty? else kind.puts(e) end end elsif kind.respond_to?(:call) kind else raise ArgumentError, "Unsupported type for ErrorHandler: #{kind}" end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
todoloo-0.0.4 | lib/todoloo/error_handler.rb |
todoloo-0.0.3 | lib/todoloo/error_handler.rb |
todoloo-0.0.2 | lib/todoloo/error_handler.rb |
todoloo-0.0.1 | lib/todoloo/error_handler.rb |