Sha256: eb16564332706dbec92d48c7df4df756f8c474a01f0ad272dbdd9c279de1640d

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

class ::Exception
  def patch_full_message
    begin
      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")
    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

2 entries across 2 versions & 1 rubygems

Version Path
eco-helpers-2.0.19 lib/eco/api/common/version_patches/exception.rb
eco-helpers-2.0.18 lib/eco/api/common/version_patches/exception.rb