Sha256: f505fe1f044392455c0e52671178a74f482bc7db2ab1238d8b4c403c2defc123
Contents?: true
Size: 1 KB
Versions: 4
Compression:
Stored size: 1 KB
Contents
class ::Exception def patch_full_message(trace_count: -1) begin msg = [] tracing = backtrace ? backtrace : [] tracing = (self.class == SystemStackError) ? tracing[1..30] : tracing[1..trace_count] 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
4 entries across 4 versions & 1 rubygems