From e0cdeb82e1c81bb2d7f55cfcb399cc8e21c7cf63 Mon Sep 17 00:00:00 2001 From: Yohei Kitamura Date: Mon, 15 Jan 2024 11:58:57 -0500 Subject: [PATCH] Fix Lorekeeper::BacktraceCleaner to support BacktraceLocation --- .github/workflows/build.yml | 2 +- CHANGELOG.md | 3 +++ lib/lorekeeper/backtrace_cleaner.rb | 1 + lib/lorekeeper/version.rb | 2 +- spec/lib/lorekeeper/backtrace_cleaner_spec.rb | 12 ++++++++++-- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74d3364..eb5d8f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: ruby: '2.7' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 561c060..31d58b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.6.3 +* Fix Lorekeeper::BacktraceCleaner to support BacktraceLocation + # 2.6.2 * Fix respond_to? method signature diff --git a/lib/lorekeeper/backtrace_cleaner.rb b/lib/lorekeeper/backtrace_cleaner.rb index e9fd029..b072f90 100644 --- a/lib/lorekeeper/backtrace_cleaner.rb +++ b/lib/lorekeeper/backtrace_cleaner.rb @@ -38,6 +38,7 @@ def filter_rails_root_backtrace(backtrace) last_index = nil result = [] backtrace.each_with_index do |line, idx| + line = line.to_s if line.start_with?(@rails_root) && @gem_path.none? { |path| line.start_with?(path) } result << line[@rails_root_size..] last_index = idx diff --git a/lib/lorekeeper/version.rb b/lib/lorekeeper/version.rb index 033f04a..0a2654b 100644 --- a/lib/lorekeeper/version.rb +++ b/lib/lorekeeper/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Lorekeeper - VERSION = '2.6.2' + VERSION = '2.6.3' end diff --git a/spec/lib/lorekeeper/backtrace_cleaner_spec.rb b/spec/lib/lorekeeper/backtrace_cleaner_spec.rb index c884adc..fa21adb 100644 --- a/spec/lib/lorekeeper/backtrace_cleaner_spec.rb +++ b/spec/lib/lorekeeper/backtrace_cleaner_spec.rb @@ -45,11 +45,13 @@ "/home/app/web/vendor/bundle/ruby/2.7.0/bin/rake:25:in `load'" ] end + let(:new_backtrace_location) { new_backtrace.map { |bt| BacktraceLocation.new('', '', bt) } } before do allow(Gem).to receive(:path).and_return(['/ruby/2.5.0', '/home/app/web/vendor/bundle/ruby/2.7.0']) stub_const('RbConfig::CONFIG', { 'rubylibdir' => '/usr/local/rvm/rubies/ruby-2.7.6/lib/ruby/2.7.0' }) stub_const('Rails', double(root: '/home/app/web')) + stub_const('BacktraceLocation', Struct.new(:path, :lineno, :to_s)) # https://github.com/rails/rails/blob/v7.1.2/activesupport/lib/active_support/syntax_error_proxy.rb#L15 end context 'Logging just an exception' do @@ -75,11 +77,17 @@ ActiveSupport::VERSION::MAJOR < 6 ? active_support_exception_less_than_v6 : active_support_exception_v6 end - it 'Does not log the lines matched with the denylist' do + it 'does not log the lines matched with the denylist' do expect(instance.clean(new_backtrace)).to eq(no_noise_backtrace) end - it 'Logs all backtraces when ActiveSupport::BacktraceCleaner and Rails.root are not defined' do + context 'with backtrace location' do + it 'does not log the lines matched with the denylist' do + expect(instance.clean(new_backtrace_location)).to eq(no_noise_backtrace) + end + end + + it 'logs all backtraces when ActiveSupport::BacktraceCleaner and Rails.root are not defined' do hide_const('ActiveSupport::BacktraceCleaner') hide_const('Rails')