Sha256: 80cae1ad2cf79a2e6a84397713482994be1b321322eaa6b731874200d6376381

Contents?: true

Size: 1000 Bytes

Versions: 86

Compression:

Stored size: 1000 Bytes

Contents

class ::Exception
  def patch_full_message
    begin
      msg = []
      tracing   = backtrace ? backtrace : []
      tracing   = (self.class == SystemStackError) ? tracing[1..30] : tracing[1..-1]
      tracing ||= []
      msg << "\n#{tracing.first} \n#{message} (#{self.class.to_s})"
      tracing.each_with_index {|bt, i| msg << "#{" "*8}#{i+1}: from #{bt}"}
      msg.join("\n")
    rescue Exception => e
      puts "Something is wrong with 'patch_full_message': #{e}"
    end
  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
    self.extend mod
  end

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

Version data entries

86 entries across 86 versions & 1 rubygems

Version Path
eco-helpers-2.3.2 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.2.5 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.2.4 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.2.3 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.2.2 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.2.1 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.12 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.11 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.10 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.9 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.8 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.7 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.6 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.5 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.4 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.3 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.2 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.1.1 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.68 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.67 lib/eco/api/common/version_patches/exception.rb