Skip to content

#shush_backtraces doesn't clean the backtrace_locations #739

Open
@amomchilov

Description

@amomchilov

The Spring::Application#shush_backtraces method strips out Spring stackframes from the exception's backtrace, but not its backtrace_locations:

$!.backtrace.reject! { |line| line.start_with?(lib) } unless $!.backtrace.frozen?

This causes at least 2 issues:

  1. The backtrace and backtrace_locations become out of sync, and only when running in Spring.
  2. It breaks the downstream behaviour of ActiveSupport::ErrorReporter, whose #report method will clean itself off the top of the stack. Since the top of the stack will be these 2 Spring frames, its logic won't remove any of the frames.

Example

#!/opt/rubies/3.4.2/bin/ruby

begin
 raise
rescue => e
end

puts "\nbacktrace:"
puts e.backtrace.first(2)

puts "\nbacktrace_locations:"
puts e.backtrace_locations.first(4)

Output (truncated):

$ bundle exec rails runner demo.rb
Running via Spring preloader in process 33573
running spring after_fork

backtrace
.../demo.rb:4:in '<main>'
.../gems/rails-8b00d0985f88/railties/lib/rails/commands/runner/runner_command.rb:44:in 'Kernel.load'

backtrace_locations
.../gems/spring-4.2.1/lib/spring/application.rb:313:in 'Method#call'
.../gems/spring-4.2.1/lib/spring/application.rb:313:in 'block (2 levels) in Kernel#shush_backtraces'
.../demo.rb:4:in '<main>'
.../gems/rails-8b00d0985f88/railties/lib/rails/commands/runner/runner_command.rb:44:in 'Kernel.load'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions