ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
@ 2020-12-27 10:03 nodai2h.ITC
  2020-12-27 11:06 ` [ruby-core:101739] " mame
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: nodai2h.ITC @ 2020-12-27 10:03 UTC (permalink / raw)
  To: ruby-core

Issue #17479 has been reported by neg_hide (Hidenori Negishi).

----------------------------------------
Feature #17479: Enable to get "--backtrace-limit" value by "$-B"
https://bugs.ruby-lang.org/issues/17479

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:101739] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
  2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
@ 2020-12-27 11:06 ` mame
  2020-12-27 16:03 ` [ruby-core:101745] " eregontp
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mame @ 2020-12-27 11:06 UTC (permalink / raw)
  To: ruby-core

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


+1 if we can provide `-B` option too.

----------------------------------------
Feature #17479: Enable to get "--backtrace-limit" value by "$-B"
https://bugs.ruby-lang.org/issues/17479#change-89561

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:101745] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
  2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
  2020-12-27 11:06 ` [ruby-core:101739] " mame
@ 2020-12-27 16:03 ` eregontp
  2020-12-28 14:47 ` [ruby-core:101782] " nodai2h.ITC
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: eregontp @ 2020-12-27 16:03 UTC (permalink / raw)
  To: ruby-core

Issue #17479 has been updated by Eregon (Benoit Daloze).


What's the use case?
I think we should encourage to use `Exception#full_message`, and that could default to apply the limit.
Related: https://github.com/ruby/ruby/commit/f6a080047e960e8b1821a97850830286ce9dee1c#commitcomment-45451705

----------------------------------------
Feature #17479: Enable to get "--backtrace-limit" value by "$-B"
https://bugs.ruby-lang.org/issues/17479#change-89567

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:101782] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
  2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
  2020-12-27 11:06 ` [ruby-core:101739] " mame
  2020-12-27 16:03 ` [ruby-core:101745] " eregontp
@ 2020-12-28 14:47 ` nodai2h.ITC
  2021-01-13  5:50 ` [ruby-core:102049] " matz
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: nodai2h.ITC @ 2020-12-28 14:47 UTC (permalink / raw)
  To: ruby-core

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 `<main>'
```

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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:102049] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
  2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
                   ` (2 preceding siblings ...)
  2020-12-28 14:47 ` [ruby-core:101782] " nodai2h.ITC
@ 2021-01-13  5:50 ` matz
  2021-01-13  7:10 ` [ruby-core:102055] " merch-redmine
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: matz @ 2021-01-13  5:50 UTC (permalink / raw)
  To: ruby-core

Issue #17479 has been updated by matz (Yukihiro Matsumoto).


I am OK with introducing a way to get the limit. But I am strongly opposed to `$-B`. Any other idea?

Matz.


----------------------------------------
Feature #17479: Enable to get "--backtrace-limit" value by "$-B"
https://bugs.ruby-lang.org/issues/17479#change-89905

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:102055] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
  2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
                   ` (3 preceding siblings ...)
  2021-01-13  5:50 ` [ruby-core:102049] " matz
@ 2021-01-13  7:10 ` merch-redmine
  2021-01-14 13:20 ` [ruby-core:102092] " eregontp
  2021-01-15 14:44 ` [ruby-core:102105] " nodai2h.ITC
  6 siblings, 0 replies; 8+ messages in thread
From: merch-redmine @ 2021-01-13  7:10 UTC (permalink / raw)
  To: ruby-core

Issue #17479 has been updated by jeremyevans0 (Jeremy Evans).


matz (Yukihiro Matsumoto) wrote in #note-4:
> I am OK with introducing a way to get the limit. But I am strongly opposed to `$-B`. Any other idea?

If we are OK with this being a constant and not a variable, `RUBY_BACKTRACE_LIMIT`.

----------------------------------------
Feature #17479: Enable to get "--backtrace-limit" value by "$-B"
https://bugs.ruby-lang.org/issues/17479#change-89911

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:102092] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
  2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
                   ` (4 preceding siblings ...)
  2021-01-13  7:10 ` [ruby-core:102055] " merch-redmine
@ 2021-01-14 13:20 ` eregontp
  2021-01-15 14:44 ` [ruby-core:102105] " nodai2h.ITC
  6 siblings, 0 replies; 8+ messages in thread
From: eregontp @ 2021-01-14 13:20 UTC (permalink / raw)
  To: ruby-core

Issue #17479 has been updated by Eregon (Benoit Daloze).


neg_hide (Hidenori Negishi) wrote in #note-3:
> 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.

The message is included in `Exception#full_message`.
And Exception#backtrace is just Strings too anyway.
I think duplicating the code to format an exception is just a high chance to reimplement it incorrectly (e.g., not handling causes, highlighting, etc correctly).

I see your point that `Exception#full_message` defaults to use the `--backtrace-limit`.
I think what we need is a `backtrace_limit` option to `Exception#full_message`, and a way to get the value (`Thread::Backtrace.limit` sounds fine).

----------------------------------------
Feature #17479: Enable to get "--backtrace-limit" value by "$-B"
https://bugs.ruby-lang.org/issues/17479#change-89949

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ruby-core:102105] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B"
  2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
                   ` (5 preceding siblings ...)
  2021-01-14 13:20 ` [ruby-core:102092] " eregontp
@ 2021-01-15 14:44 ` nodai2h.ITC
  6 siblings, 0 replies; 8+ messages in thread
From: nodai2h.ITC @ 2021-01-15 14:44 UTC (permalink / raw)
  To: ruby-core

Issue #17479 has been updated by neg_hide (Hidenori Negishi).


I agree with `Thread::Backtrace.limit` because I think it's easy to understand.

----------------------------------------
Feature #17479: Enable to get "--backtrace-limit" value by "$-B"
https://bugs.ruby-lang.org/issues/17479#change-89962

* 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/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-15 14:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-27 10:03 [ruby-core:101734] [Ruby master Feature#17479] Enable to get "--backtrace-limit" value by "$-B" nodai2h.ITC
2020-12-27 11:06 ` [ruby-core:101739] " mame
2020-12-27 16:03 ` [ruby-core:101745] " eregontp
2020-12-28 14:47 ` [ruby-core:101782] " nodai2h.ITC
2021-01-13  5:50 ` [ruby-core:102049] " matz
2021-01-13  7:10 ` [ruby-core:102055] " merch-redmine
2021-01-14 13:20 ` [ruby-core:102092] " eregontp
2021-01-15 14:44 ` [ruby-core:102105] " nodai2h.ITC

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).