Skip to content

Clean ActiveRecord backtraces as if they are in the source #1350

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

Merged
merged 1 commit into from
Jul 8, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/cases/helper_sqlserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Bundler.require :default, :development
require "pry"
require "support/core_ext/query_cache"
require "support/core_ext/backtrace_cleaner"
require "support/minitest_sqlserver"
require "support/test_in_memory_oltp"
require "support/table_definition_sqlserver"
Expand Down
36 changes: 36 additions & 0 deletions test/support/core_ext/backtrace_cleaner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

# Need to handle `ActiveRecord` lines like they are in the source rather than in the Rails gem.
module SQLServer
module BacktraceCleaner
extend ActiveSupport::Concern

private

def add_gem_filter
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
return if gems_paths.empty?

gems_regexp = %r{\A(#{gems_paths.join("|")})/(bundler/)?gems/([^/]+)-([\w.]+)/(.*)}
gems_result = '\3 (\4) \5'

add_filter do |line|
if line.match?(/activerecord/)
line
else
line.sub(gems_regexp, gems_result)
end
end
end

def add_gem_silencer
add_silencer do |line|
ActiveSupport::BacktraceCleaner::FORMATTED_GEMS_PATTERN.match?(line) && !/activerecord/.match?(line)
end
end
end
end

ActiveSupport.on_load(:active_record) do
ActiveSupport::BacktraceCleaner.prepend(SQLServer::BacktraceCleaner)
end
Loading