Skip to content

Commit

Permalink
Merge pull request #189 from rohitpaulk/ignored-paths
Browse files Browse the repository at this point in the history
Ignore ./vendor & ./bin from stacktraces
  • Loading branch information
dejan authored Apr 13, 2024
2 parents 78bd910 + fcbd88a commit 1dfdb48
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
12 changes: 12 additions & 0 deletions meta_request/lib/meta_request/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,17 @@ def storage_pool_size
def source_path
@source_path ||= ENV['SOURCE_PATH'] || Rails.root.to_s
end

# List of relative paths inside Rails app. Used in Location calculation.
def ignored_paths
self.ignored_paths = %w[bin vendor] unless @ignored_paths
@ignored_paths
end

def ignored_paths=(paths)
@ignored_paths = paths.map do |path|
Rails.root.join(path).to_s.freeze
end.freeze
end
end
end
12 changes: 11 additions & 1 deletion meta_request/lib/meta_request/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Utils
module_function

def dev_callsite(caller)
app_line = caller.detect { |c| c.start_with? MetaRequest.rails_root }
app_line = caller.detect { |c| valid_application_path? c }
return nil unless app_line

_, filename, _, line, _, method = app_line.split(/^(.*?)(:(\d+))(:in `(.*)')?$/)
Expand All @@ -24,5 +24,15 @@ def sub_source_path(path)

path.sub(rails_root, source_path)
end

def valid_application_path?(path)
path.start_with?(MetaRequest.rails_root) && !ignored_path?(path)
end

def ignored_path?(path)
MetaRequest.config.ignored_paths.any? do |ignored_path|
path.start_with?(ignored_path.to_s)
end
end
end
end
25 changes: 25 additions & 0 deletions meta_request/spec/meta_request/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,29 @@
# revert configuration
MetaRequest.config.source_path = MetaRequest.rails_root
end

it 'ignores ignored paths' do
filename = File.join(MetaRequest.rails_root, 'test_file.rb')
line = 87
method = 'app_func'
vendor_filename = File.join(MetaRequest.rails_root, 'vendor', 'test_file.rb')

stacktrace = [
"/gem/gem_file.rb:1:in `func'`",
"#{vendor_filename}:#{line}:in `#{method}'",
"#{filename}:#{line}:in `#{method}'",
"#{vendor_filename}:#{line}:in `#{method}'",
"/gem/gem_file.rb:1:in `func2'`"
]

expect(MetaRequest::Utils.dev_callsite(stacktrace)).to eq(
filename: filename, line: line, method: method
)

stacktrace = [
"#{vendor_filename}:#{line}:in `#{method}'"
]

expect(MetaRequest::Utils.dev_callsite(stacktrace)).to be(nil)
end
end
2 changes: 1 addition & 1 deletion meta_request/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

module Rails
def self.root
Dir.pwd
Pathname(Dir.pwd)
end
end

Expand Down

0 comments on commit 1dfdb48

Please sign in to comment.