Sha256: 0db937a6f35fec5b024b708ecc8f999bf3cf682f6fed64ffd9c19e1460845930

Contents?: true

Size: 962 Bytes

Versions: 34

Compression:

Stored size: 962 Bytes

Contents

# frozen_string_literal: true

module DeepCover
  module Tools::TruncateBacktrace
    def truncate_backtrace(backtrace, extra_context: 10)
      backtrace = backtrace.backtrace if backtrace.is_a?(Exception)
      trace_lines = backtrace.uniq

      keep_from_begin = 0
      keep_from_end = backtrace.size - 1

      trace_lines.each do |line|
        from_begin = backtrace.index(line)
        from_end = backtrace.rindex(line)
        if from_begin <= backtrace.size - 1 - from_end
          keep_from_begin = [keep_from_begin, from_begin].max
        else
          keep_from_end = [keep_from_end, from_end].min
        end
      end

      keep_from_begin += extra_context
      keep_from_end -= extra_context

      return backtrace if keep_from_begin + 5 >= keep_from_end

      result = backtrace[0..keep_from_begin]
      result << "... #{keep_from_end - keep_from_begin - 1} levels..."
      result.concat backtrace[keep_from_end..-1]
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
deep-cover-core-1.1.0 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-1.0.0 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.8.1 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.8.0 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.10 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.9 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.8 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.7 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.6 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.5 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.4 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.3 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.2 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.1 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.7.0 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.6.4 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.6.3 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-core-0.6.3.pre lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-0.6.2 lib/deep_cover/tools/truncate_backtrace.rb
deep-cover-0.6.1 lib/deep_cover/tools/truncate_backtrace.rb