From: "Eregon (Benoit Daloze)" Date: 2022-11-10T16:41:24+00:00 Subject: [ruby-core:110696] [Ruby master Feature#19117] Include the method owner in backtraces, not just the method name Issue #19117 has been updated by Eregon (Benoit Daloze). Refinements are already formatted like: ``` $ ruby -e 'module M; refine String do; p self; end; end' # ``` I think there is no need to change anything there. For methods on a singleton class, I believe we should use the `.` notation, so `Process.pid` instead of `##pid`. We cannot avoid addresses/`object_id`'s in the output, there can be truly anonymous modules. But I agree that a changing address is not great. What TruffleRuby does is use the `object_id` for `Kernel#inspect`/`Module#inspect`. That's stable. I think CRuby should do the same. The changing inspect for the same object is indeed very confusing, cc @tenderlovemaking: ``` > obj=Object.new => # > GC.compact > obj => # ``` It doesn't need to be `object_id`, but it needs to be stable per object, so using `object_id` seems nice and avoids the need for another kind of identity hash/id (and the storage for it). It could also be for instance the `Kernel#hash` (the identity hash) of that object, and that is stable. ---------------------------------------- Feature #19117: Include the method owner in backtraces, not just the method name https://bugs.ruby-lang.org/issues/19117#change-100037 * Author: byroot (Jean Boussier) * Status: Open * Priority: Normal ---------------------------------------- ``` 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 `
' ``` 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 `
' ``` 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 -- https://bugs.ruby-lang.org/ Unsubscribe: