From: nodai2h.ITC@... Date: 2020-12-28T14:47:37+00:00 Subject: [ruby-core:101782] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" Issue #17479 has been updated by neg_hide (Hidenori Negishi). I am making a library that makes error messages easier to read. Therefore, instead of using `Exception#full_message`, I need to analyze the Exception and output the error message myself. For example, suppose I have a script like this: ```ruby def foo require "typo_library_name" end def bar foo end bar ``` When I execute `ruby --backtrace-limit=1 script.rb` in a normal environment, only the backtrace of kernel_require.rb is displayed as shown below, which makes it difficult to understand the true cause of the error. (The same is true for the string obtained from `Exception#full_message`.) ``` /home/myname/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb:85:in `require': cannot load such file -- typo_library_name (LoadError) from /home/myname/.rbenv/versions/3.0.0/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb:85:in `require' ... 3 levels... ``` When I use my library, it omits the backtraces of kernel_require.rb and outputs them, so the error message looks like this. ``` ruby.rb:2:in `foo': cannot load such file -- typo_library_name (LoadError) from ruby.rb:2:in `foo' from ruby.rb:6:in `bar' from ruby.rb:9:in `
' ``` This process is impossible for `Exception#full_message`. So I have to output the error message myself. However, I want the output to look like this: ``` ruby.rb:2:in `foo': cannot load such file -- typo_library_name (LoadError) from ruby.rb:2:in `foo' ... 2 levels... ``` That's why I need a value for "--backtrace-limit". ---------------------------------------- Feature #17479: Enable to get "--backtrace-limit" value by "$-B" https://bugs.ruby-lang.org/issues/17479#change-89610 * Author: neg_hide (Hidenori Negishi) * Status: Open * Priority: Normal ---------------------------------------- # Background There is currently no way to get "--backtrace-limit" value when outputing backtraces from my script, so I have to ignore this value and output backtraces. In order to be able to output according to "--backtrace-limit" value, I need a API to get this value from the Ruby side. # Proposal I propose a readonly built-in variable "$-B" to get "--backtrace-limit" value. ``` ruby # ruby --backtrace-limit=3 script.rb puts $-B # => 3 ``` -- https://bugs.ruby-lang.org/ Unsubscribe: