Sha256: eb85ef10c7f331967b14760186a169f9142994e2fd183f561b8d23066dd9bd96

Contents?: true

Size: 737 Bytes

Versions: 30

Compression:

Stored size: 737 Bytes

Contents

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

30 entries across 30 versions & 1 rubygems

Version Path
eco-helpers-2.0.17 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.16 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.15 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.14 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.13 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.12 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.11 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.10 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.9 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.8 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.7 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.6 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.5 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.4 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.3 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.2 lib/eco/api/common/version_patches/exception.rb
eco-helpers-1.5.15 lib/eco/api/common/version_patches/exception.rb
eco-helpers-1.5.14 lib/eco/api/common/version_patches/exception.rb
eco-helpers-1.5.13 lib/eco/api/common/version_patches/exception.rb
eco-helpers-1.5.12 lib/eco/api/common/version_patches/exception.rb