ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "mame (Yusuke Endoh) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "mame (Yusuke Endoh)" <noreply@ruby-lang.org>
Subject: [ruby-core:116312] [Ruby master Feature#19117] Include the method owner in backtraces, not just the method name
Date: Fri, 19 Jan 2024 05:39:36 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-106336.20240119053935.7941@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19117.20221110121311.7941@ruby-lang.org

Issue #19117 has been updated by mame (Yusuke Endoh).


I prototyped this proposal: https://github.com/ruby/ruby/pull/9605

Fortunately, this would bring neither perrformance degredation nor extra memory usage when an exception is raised because I just replaced the method id with the method entry object in Thread::Backtrace::Location. (To get the method id, we need to read it via the method entry object, but I believe it is ignorable.)

The notation is as follows.

* Instance methods of named classes are `ClassName#method_name`.
* Class methods for named classes are `ClassName.method_name`.
* Only `method_name` otherwise

I think I properly support `block in ClassName#method_name` and so on.

```
$ cat test.rb
def toplevel = raise

class Foo
  def self.class_meth = toplevel

  def instance_meth = Foo.class_meth
end

obj = Foo.new

def obj.singleton_meth = instance_meth

obj.singleton_meth

$ ./miniruby test.rb
test.rb:1:in 'Object#toplevel': unhandled exception
        from test.rb:4:in 'Foo.class_meth'
        from test.rb:6:in 'Foo#instance_meth'
        from test.rb:11:in 'singleton_meth'
        from test.rb:13:in '<main>'
```

@byroot What do you think?

This causes some tests to fail, but I haven't fixed the test yet.

----------------------------------------
Feature #19117: Include the method owner in backtraces, not just the method name
https://bugs.ruby-lang.org/issues/19117#change-106336

* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
* Target version: 3.4
----------------------------------------
```
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



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

  parent reply	other threads:[~2024-01-19  5:39 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 12:13 [ruby-core:110683] [Ruby master Feature#19117] Include the method owner in backtraces, not just the method name byroot (Jean Boussier)
2022-11-10 12:28 ` [ruby-core:110685] " zverok (Victor Shepelev)
2022-11-10 13:08 ` [ruby-core:110686] " Eregon (Benoit Daloze)
2022-11-10 13:11 ` [ruby-core:110687] " Eregon (Benoit Daloze)
2022-11-10 13:29 ` [ruby-core:110688] " byroot (Jean Boussier)
2022-11-10 13:50 ` [ruby-core:110691] " kjtsanaktsidis (KJ Tsanaktsidis)
2022-11-10 16:41 ` [ruby-core:110696] " Eregon (Benoit Daloze)
2022-11-11  0:23 ` [ruby-core:110701] " byroot (Jean Boussier)
2022-11-11 10:01 ` [ruby-core:110702] " Eregon (Benoit Daloze)
2022-11-11 23:37 ` [ruby-core:110712] " byroot (Jean Boussier)
2022-11-12  2:08 ` [ruby-core:110717] " kjtsanaktsidis (KJ Tsanaktsidis)
2022-11-12  2:24 ` [ruby-core:110719] " kjtsanaktsidis (KJ Tsanaktsidis)
2022-11-12  3:30 ` [ruby-core:110720] " byroot (Jean Boussier)
2022-11-12 12:24 ` [ruby-core:110724] " Eregon (Benoit Daloze)
2022-11-14  8:03 ` [ruby-core:110745] " mame (Yusuke Endoh)
2022-11-16 16:20 ` [ruby-core:110778] " ivoanjo (Ivo Anjo)
2022-11-16 16:25 ` [ruby-core:110779] " Dan0042 (Daniel DeLorme)
2022-11-16 16:40 ` [ruby-core:110780] " byroot (Jean Boussier)
2022-11-16 16:57 ` [ruby-core:110782] " Eregon (Benoit Daloze)
2022-11-16 17:01 ` [ruby-core:110783] " Eregon (Benoit Daloze)
2022-11-16 18:32 ` [ruby-core:110784] " Dan0042 (Daniel DeLorme)
2022-12-02  2:33 ` [ruby-core:111140] " mame (Yusuke Endoh)
2023-11-30  7:01 ` [ruby-core:115539] " mame (Yusuke Endoh) via ruby-core
2023-11-30  7:27 ` [ruby-core:115541] " byroot (Jean Boussier) via ruby-core
2023-11-30 12:32 ` [ruby-core:115546] " Eregon (Benoit Daloze) via ruby-core
2024-01-19  5:39 ` mame (Yusuke Endoh) via ruby-core [this message]
2024-01-19  9:11 ` [ruby-core:116320] " byroot (Jean Boussier) via ruby-core
2024-01-19  9:37 ` [ruby-core:116321] " byroot (Jean Boussier) via ruby-core
2024-01-19 15:02 ` [ruby-core:116334] " Dan0042 (Daniel DeLorme) via ruby-core
2024-01-19 15:25 ` [ruby-core:116335] " byroot (Jean Boussier) via ruby-core
2024-01-19 15:36 ` [ruby-core:116337] " Dan0042 (Daniel DeLorme) via ruby-core
2024-01-19 15:42 ` [ruby-core:116338] " byroot (Jean Boussier) via ruby-core
2024-01-19 19:38 ` [ruby-core:116339] " Dan0042 (Daniel DeLorme) via ruby-core
2024-01-19 19:48 ` [ruby-core:116340] " byroot (Jean Boussier) via ruby-core
2024-01-20  0:58 ` [ruby-core:116343] " mame (Yusuke Endoh) via ruby-core
2024-01-20 11:04 ` [ruby-core:116346] " byroot (Jean Boussier) via ruby-core
2024-01-20 16:50 ` [ruby-core:116348] " Dan0042 (Daniel DeLorme) via ruby-core
2024-02-13  9:42 ` [ruby-core:116693] " ko1 (Koichi Sasada) via ruby-core
2024-02-13 10:28 ` [ruby-core:116694] " byroot (Jean Boussier) via ruby-core
2024-02-13 10:58 ` [ruby-core:116695] " Eregon (Benoit Daloze) via ruby-core
2024-02-13 18:02 ` [ruby-core:116705] " ko1 (Koichi Sasada) via ruby-core
2024-02-13 18:14 ` [ruby-core:116706] " Eregon (Benoit Daloze) via ruby-core
2024-02-14  5:10 ` [ruby-core:116729] " matz (Yukihiro Matsumoto) via ruby-core
2024-02-16  8:39 ` [ruby-core:116793] " byroot (Jean Boussier) via ruby-core
2024-02-16 11:34 ` [ruby-core:116796] " mame (Yusuke Endoh) via ruby-core
2024-02-16 11:38 ` [ruby-core:116797] " byroot (Jean Boussier) via ruby-core
2024-02-16 20:31 ` [ruby-core:116807] " Eregon (Benoit Daloze) via ruby-core
2024-02-16 21:45 ` [ruby-core:116809] " Dan0042 (Daniel DeLorme) via ruby-core
2024-02-17  3:50 ` [ruby-core:116812] " mame (Yusuke Endoh) via ruby-core
2024-02-17 10:33 ` [ruby-core:116818] " Eregon (Benoit Daloze) via ruby-core
2024-02-17 10:48 ` [ruby-core:116821] " Eregon (Benoit Daloze) via ruby-core
2024-03-21 20:08 ` [ruby-core:117285] " Eregon (Benoit Daloze) via ruby-core
2024-03-21 20:08 ` [ruby-core:117286] " Eregon (Benoit Daloze) via ruby-core

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-106336.20240119053935.7941@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    --cc=noreply@ruby-lang.org \
    --cc=ruby-core@ml.ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).