Sha256: 6abb16cd1bf474b49dc3bf1385e4d8bbca66097e7f9ae35fcca4dd47ca748eb6

Contents?: true

Size: 1.13 KB

Versions: 28

Compression:

Stored size: 1.13 KB

Contents

class ::Exception
  def patch_full_message(trace_count: -1)
    tracing   = backtrace || []
    first_ln  = tracing[0]
    tracing   = tracing[1..trace_count]
    tracing   = tracing[1..30] if instance_of?(SystemStackError)
    tracing ||= []

    msg = []
    msg << "\n#{first_ln} \n#{message} (#{self.class})"
    tracing.each_with_index do |bt, i|
      msg << "#{" " * 8}#{i + 1}: from #{bt}"
    end

    unless cause.nil?
      msg << "\nCAUSE:"
      msg << cause.patch_full_message(trace_count: trace_count)
    end

    msg.join("\n")
  rescue StandardError => e
    puts "Something is wrong with 'patch_full_message': #{e}"
  end
end

# To extend an exception message preserving same exception object
# @see https://stackoverflow.com/a/30133010/4352306
Exception.class_eval do
  def prepend_message(message)
    mod = Module.new do
      define_method :to_s do
        String(message) + super()
      end
    end
    extend mod
  end

  def append_message(message)
    mod = Module.new do
      define_method :to_s do
        super() + String(message)
      end
    end
    extend mod
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/common/version_patches/exception.rb
eco-rake-0.2.6 lib/eco-rake/patches/exception.rb
eco-helpers-3.0.20 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.19 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.18 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.17 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.16 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.15 lib/eco/api/common/version_patches/exception.rb
eco-rake-0.2.5 lib/eco-rake/patches/exception.rb
eco-helpers-3.0.14 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.13 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.12 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.11 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.10 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.9 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.8 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.7 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.6 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.5 lib/eco/api/common/version_patches/exception.rb
eco-helpers-3.0.4 lib/eco/api/common/version_patches/exception.rb