Sha256: 2524068594ab520302f1abf42861776fc0d5092270beb879ba51d59fdc738979

Contents?: true

Size: 1.07 KB

Versions: 20

Compression:

Stored size: 1.07 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

# encoding=utf-8

module Exceptions
  def self.error_handler(name = '', opts = {}, backtrace: $@, format_string: "\nError: %{name} -- %{message}", color_symbol: :red, take_count: 16)
    warn(error = format(format_string,
                        { name: name, message: $! }).send(color_symbol))
    if backtrace
      warn(backtrace.select do |s|
             s.include? 'markdown_exec'
           end.reject { |s| s.include? 'vendor' }.take(take_count).map.with_index { |line, ind| " *   #{ind}: #{line}" })
    end

    binding.pry if $tap_enable
    raise ArgumentError, error unless opts.fetch(:abort, true)

    exit 1
  end

  def self.warn_format(message = '', opts = {})
    warn(
      error = format(
        opts.fetch(:format_string, "\nError: %{error}"),
        { error: message }
      ).send(opts.fetch(:color_symbol, :yellow))
    )
    # warn(caller.take(4).map.with_index { |line, ind| " *   #{ind}: #{line}" })

    binding.pry if $tap_enable
    raise ArgumentError, error unless opts.fetch(:abort, false)

    exit 1
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
markdown_exec-2.3.0 lib/exceptions.rb
markdown_exec-2.2.0 lib/exceptions.rb
markdown_exec-2.1.0 lib/exceptions.rb
markdown_exec-2.0.8.4 lib/exceptions.rb
markdown_exec-2.0.8.3 lib/exceptions.rb
markdown_exec-2.0.8.2 lib/exceptions.rb
markdown_exec-2.0.8.1 lib/exceptions.rb
markdown_exec-2.0.8 lib/exceptions.rb
markdown_exec-2.0.7 lib/exceptions.rb
markdown_exec-2.0.6 lib/exceptions.rb
markdown_exec-2.0.5 lib/exceptions.rb
markdown_exec-2.0.4 lib/exceptions.rb
markdown_exec-2.0.3.2 lib/exceptions.rb
markdown_exec-2.0.3.1 lib/exceptions.rb
markdown_exec-2.0.3 lib/exceptions.rb
markdown_exec-2.0.2 lib/exceptions.rb
markdown_exec-2.0.1 lib/exceptions.rb
markdown_exec-2.0.0 lib/exceptions.rb
markdown_exec-1.8.9 lib/exceptions.rb
markdown_exec-1.8.8 lib/exceptions.rb