Project

General

Profile

Actions

Bug #17466

closed

Inconsistent backtrace order in Ruby 3.0

Added by jnchito (Junichi Ito) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.0.0dev (2020-12-19T22:13:08Z master 6343a81129) [x86_64-darwin20]
[ruby-core:101665]

Description

I found the backtrace order is different between ruby sample.rb and irb in Ruby 3.0.

# sample.rb
puts RUBY_DESCRIPTION
class A
  def hoge
    fuga
  end

  def fuga
    1/0
  end
end
A.new.hoge
$ ruby sample.rb
ruby 3.0.0dev (2020-12-19T22:13:08Z master 6343a81129) [x86_64-darwin20]
sample.rb:8:in `/': divided by 0 (ZeroDivisionError)
	from sample.rb:8:in `fuga'
	from sample.rb:4:in `hoge'
	from sample.rb:11:in `<main>'
$ irb --prompt simple
>> puts RUBY_DESCRIPTION
ruby 3.0.0dev (2020-12-19T22:13:08Z master 6343a81129) [x86_64-darwin20]
=> nil
?> class A
?>   def hoge
?>     fuga
?>   end
?> 
?>   def fuga
?>     1/0
?>   end
>> end
=> :fuga
>> A.new.hoge
Traceback (most recent call last):
        7: from /Users/jnito/.rbenv/versions/3.0.0-dev/bin/irb:23:in `<main>'
        6: from /Users/jnito/.rbenv/versions/3.0.0-dev/bin/irb:23:in `load'
        5: from /Users/jnito/.rbenv/versions/3.0.0-dev/lib/ruby/gems/3.0.0/gems/irb-1.2.7/exe/irb:11:in `<top (required)>'
        4: from (irb):11:in `<main>'
        3: from (irb):4:in `hoge'
        2: from (irb):8:in `fuga'
        1: from (irb):8:in `/'
ZeroDivisionError (divided by 0)

I'd like to have the same order because such an inconsistent results would confuse developers (especially beginners).

This issue is related to https://bugs.ruby-lang.org/issues/8661


Files

Screen Shot 2020-12-24 at 8.38.53.png (992 KB) Screen Shot 2020-12-24 at 8.38.53.png jnchito (Junichi Ito), 12/23/2020 11:41 PM

Updated by jnchito (Junichi Ito) almost 4 years ago

I'd like to have the same order because such an inconsistent results would confuse developers (especially beginners).

Please let me add more information.

I am the author of a book called "プロを目指す人のためのRuby入門"( https://gihyo.jp/book/2017/978-4-7741-9397-7 ). I wrote how to read backtrace in it (please see the attached image.) I might revise it for Ruby 3.0. If the backtrace is different between ruby command and irb, I have to describe context and switch backtrace example each time. It would increase the cost of writing and confuse readers who are struggling with errors.

Updated by marcandre (Marc-Andre Lafortune) almost 4 years ago

  • Assignee set to aycabta (aycabta .)

The order of the backtrace was reverse for 2.7 and switched back for 3.0, see #8661

Indeed, irb probably needs to be updated to reflect that.

Updated by Eregon (Benoit Daloze) almost 4 years ago

Could IRB use Exception#full_message (+ filter with Exception#set_backtrace, or filter the output of #full_message)?
I was also surprised that IRB has its own backtrace formatting logic.

Actions #4

Updated by aycabta (aycabta .) almost 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|917050220a1fd41bdb3e50ea54a200b0c285bcd4.


[ruby/irb] Use Exception#full_message to show backtrace in the correct order

[Bug #17466]

https://github.com/ruby/irb/commit/1c76845cca

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0