Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore ./vendor & ./bin from stacktraces #189

Merged
merged 1 commit into from Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions meta_request/lib/meta_request/config.rb
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
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
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
Expand Up @@ -14,7 +14,7 @@

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

Expand Down