Project

General

Profile

Actions

Feature #19117

closed

Include the method owner in backtraces, not just the method name

Added by byroot (Jean Boussier) over 2 years ago. Updated about 1 year ago.

Status:
Closed
Target version:
[ruby-core:110683]

Description

module Foo
  class Bar
    def inspect
      1 + '1'
    end
  end
end

p Foo::Bar.new

This code produce the following backtrace:

/tmp/foo.rb:4:in `+': String can't be coerced into Integer (TypeError)
	from /tmp/foo.rb:4:in `inspect'
	from /tmp/foo.rb:9:in `p'
	from /tmp/foo.rb:9:in `<main>'

This works, but on large codebases and large backtraces the method name isn't always all that revealing, most of the time you need to open many of the locations listed in the backtrace to really understand what is going on.

I propose that we also include the owner name:

/tmp/foo.rb:4:in `Integer#+': String can't be coerced into Integer (TypeError)
	from /tmp/foo.rb:4:in `Foo::Bar#inspect'
	from /tmp/foo.rb:9:in `Kernel#p'
	from /tmp/foo.rb:9:in `<main>'

I believe that in many case it would allow to much better understand the backtrace without having to jump back and forth between it and the source code.

This is inspired by @ivoanjo 's backtracie gem: https://github.com/ivoanjo/backtracie


Related issues 2 (0 open2 closed)

Related to Ruby - Feature #16495: Inconsistent quotes in error messagesClosedmatz (Yukihiro Matsumoto)Actions
Related to Ruby - Feature #20275: Avoid extra backtrace entries for rescue and ensureClosedEregon (Benoit Daloze)Actions
Actions

Also available in: Atom PDF

Like7
Like0Like0Like0Like1Like0Like0Like0Like0Like0Like0Like0Like1Like0Like0Like0Like0Like0Like0Like0Like0Like1Like1Like1Like0Like0Like1Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like1Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0