Sha256: 59c6c26a3d15d6e5fef34a7d23f1bb8925197c7749d911e406488b51a8e22c0f

Contents?: true

Size: 964 Bytes

Versions: 11

Compression:

Stored size: 964 Bytes

Contents

class ::Exception
  def patch_full_message(trace_count: -1)
    msg = []
    tracing   = backtrace || []
    tracing   = instance_of?(SystemStackError) ? tracing[1..30] : tracing[1..trace_count]
    tracing ||= []
    msg << "\n#{tracing.first} \n#{message} (#{self.class})"
    tracing.each_with_index {|bt, i| msg << "#{" "*8}#{i+1}: from #{bt}"}
    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

11 entries across 11 versions & 1 rubygems

Version Path
eco-helpers-2.7.18 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.17 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.16 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.15 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.14 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.13 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.12 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.4 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.2 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.1 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.7.0 lib/eco/api/common/version_patches/exception.rb