Skip to content

Commit

Permalink
Fix Lorekeeper::BacktraceCleaner to support BacktraceLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
ykitamura-mdsol committed Jan 15, 2024
1 parent 15c6d0f commit e0cdeb8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.6.3
* Fix Lorekeeper::BacktraceCleaner to support BacktraceLocation

# 2.6.2
* Fix respond_to? method signature

Expand Down
1 change: 1 addition & 0 deletions lib/lorekeeper/backtrace_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/lorekeeper/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Lorekeeper
VERSION = '2.6.2'
VERSION = '2.6.3'
end
12 changes: 10 additions & 2 deletions spec/lib/lorekeeper/backtrace_cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')

Expand Down

0 comments on commit e0cdeb8

Please sign in to comment.