ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120856] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
@ 2025-02-02  1:15 ennder via ruby-core
  2025-02-02 11:42 ` [ruby-core:120861] " Eregon (Benoit Daloze) via ruby-core
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ennder via ruby-core @ 2025-02-02  1:15 UTC (permalink / raw)
  To: ruby-core; +Cc: ennder

Issue #21105 has been reported by ennder (Jérôme BATAILLE).

----------------------------------------
Feature #21105: Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
https://bugs.ruby-lang.org/issues/21105

* Author: ennder (Jérôme BATAILLE)
* Status: Open
----------------------------------------
h2. Subject
Improve Ruby Stack Trace to Include Exact Error Position (Column Number)

h2. Description
Currently, when an exception occurs in Ruby, the stack trace provides the file name and line number but does not indicate the exact position (column number) where the error occurred within the line. This lack of precision can make debugging more challenging, especially in cases where multiple method calls or expressions are present on the same line.

h2. Example

<pre><code class="ruby">
class Example
  def self.run
    nil.some_method_call  # Error occurs here
  end
end

Example.run
</code></pre>

h2. Expected Behavior

The stack trace should include the column number where the error occurred, e.g.:
<pre><code>
trace.rb:4:10:in `run': undefined method `some_method_call' for nil:NilClass (NoMethodError)
</code></pre>

h2. Benefits

More precise debugging.

Easier identification of errors in complex one-liner expressions.

Better tooling support for editors and debuggers.

h2. Additional Notes
Would it be possible to add this enhancement in a future Ruby version?

Thank you for considering this request!




-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120861] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
  2025-02-02  1:15 [ruby-core:120856] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number) ennder via ruby-core
@ 2025-02-02 11:42 ` Eregon (Benoit Daloze) via ruby-core
  2025-02-13  7:30 ` [ruby-core:120969] " matz (Yukihiro Matsumoto) via ruby-core
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2025-02-02 11:42 UTC (permalink / raw)
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

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


It is already shown:
```ruby
class Example
  def self.run
    nil.foo.bar.baz
  end
end

Example.run
```

```
example.rb:3:in `run': undefined method `foo' for nil (NoMethodError)

    nil.foo.bar.baz
       ^^^^
	from example.rb:7:in `<main>'
```

Adding columns would add a lot of noise and would not be clearer than that.
So I think we can close this as "already done, just in a different/clearer way"

----------------------------------------
Feature #21105: Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
https://bugs.ruby-lang.org/issues/21105#change-111735

* Author: ennder (Jérôme BATAILLE)
* Status: Open
----------------------------------------
## Subject

Improve Ruby Stack Trace to Include Exact Error Position (Column Number)

## Description

Currently, when an exception occurs in Ruby, the stack trace provides the file name and line number but does not indicate the exact position (column number) where the error occurred within the line. This lack of precision can make debugging more challenging, especially in cases where multiple method calls or expressions are present on the same line.

## Example

``` ruby
class Example
  def self.run
    nil.some_method_call  # Error occurs here
  end
end

Example.run
```

## Expected Behavior

The stack trace should include the column number where the error occurred, e.g.:

``` ruby
trace.rb:4:10:in `run': undefined method `some_method_call' for nil:NilClass (NoMethodError)
```


## Benefits

More precise debugging.

Easier identification of errors in complex one-liner expressions.

Better tooling support for editors and debuggers.

## Additional Notes

Would it be possible to add this enhancement in a future Ruby version?

Thank you for considering this request!




-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120969] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
  2025-02-02  1:15 [ruby-core:120856] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number) ennder via ruby-core
  2025-02-02 11:42 ` [ruby-core:120861] " Eregon (Benoit Daloze) via ruby-core
@ 2025-02-13  7:30 ` matz (Yukihiro Matsumoto) via ruby-core
  2025-02-13 15:32 ` [ruby-core:120983] " mame (Yusuke Endoh) via ruby-core
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: matz (Yukihiro Matsumoto) via ruby-core @ 2025-02-13  7:30 UTC (permalink / raw)
  To: ruby-core; +Cc: matz (Yukihiro Matsumoto)

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

Status changed from Open to Closed

I like introducing the column number in the error message, but in reality, it is hard to get column numbers from the error object, and I don't think it's worth the extensive overhaul to make that possible.
Probably we will add this in the future wishlist.

Matz.


----------------------------------------
Feature #21105: Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
https://bugs.ruby-lang.org/issues/21105#change-111868

* Author: ennder (Jérôme BATAILLE)
* Status: Closed
----------------------------------------
## Subject

Improve Ruby Stack Trace to Include Exact Error Position (Column Number)

## Description

Currently, when an exception occurs in Ruby, the stack trace provides the file name and line number but does not indicate the exact position (column number) where the error occurred within the line. This lack of precision can make debugging more challenging, especially in cases where multiple method calls or expressions are present on the same line.

## Example

``` ruby
class Example
  def self.run
    nil.some_method_call  # Error occurs here
  end
end

Example.run
```

## Expected Behavior

The stack trace should include the column number where the error occurred, e.g.:

``` ruby
trace.rb:4:10:in `run': undefined method `some_method_call' for nil:NilClass (NoMethodError)
```


## Benefits

More precise debugging.

Easier identification of errors in complex one-liner expressions.

Better tooling support for editors and debuggers.

## Additional Notes

Would it be possible to add this enhancement in a future Ruby version?

Thank you for considering this request!




-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:120983] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
  2025-02-02  1:15 [ruby-core:120856] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number) ennder via ruby-core
  2025-02-02 11:42 ` [ruby-core:120861] " Eregon (Benoit Daloze) via ruby-core
  2025-02-13  7:30 ` [ruby-core:120969] " matz (Yukihiro Matsumoto) via ruby-core
@ 2025-02-13 15:32 ` mame (Yusuke Endoh) via ruby-core
  2025-02-21 18:37 ` [ruby-core:121138] " ennder via ruby-core
  2025-02-25  9:49 ` [ruby-core:121156] " mame (Yusuke Endoh) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2025-02-13 15:32 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

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


I think it is worth to display column info as `trace.rb:3:7: in 'run': ... `. When you click on it in the vscode terminal, it will open the file and jumpto that location.

However, there are numerous problems to making this happen.

* Which specific column position should be displayed: For NoMethodError, near the beginning of the method name seems appropriate. However, for ArgumentError, you may want to indicate the position of the argument that caused the problem. Appropriate column locations would change on a node-by-node and exception-by-exception basis.
* Overhead: Currently, the interpreter bytecode only holds the node IDs, not the column information. We need to store column information for each bytecode instruction, which will require memory overhead, or, to reopen and reparse the source file to restore column information each time a backtrace is generated, which will require performance overhead.
* Compatibility: There are a small number of projects that parse backtrace strings using regular expressions. The addition of column numbers will cause that parsing to stop working.




----------------------------------------
Feature #21105: Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
https://bugs.ruby-lang.org/issues/21105#change-111885

* Author: ennder (Jérôme BATAILLE)
* Status: Closed
----------------------------------------
## Subject

Improve Ruby Stack Trace to Include Exact Error Position (Column Number)

## Description

Currently, when an exception occurs in Ruby, the stack trace provides the file name and line number but does not indicate the exact position (column number) where the error occurred within the line. This lack of precision can make debugging more challenging, especially in cases where multiple method calls or expressions are present on the same line.

## Example

``` ruby
class Example
  def self.run
    nil.some_method_call  # Error occurs here
  end
end

Example.run
```

## Expected Behavior

The stack trace should include the column number where the error occurred, e.g.:

``` ruby
trace.rb:4:10:in `run': undefined method `some_method_call' for nil:NilClass (NoMethodError)
```


## Benefits

More precise debugging.

Easier identification of errors in complex one-liner expressions.

Better tooling support for editors and debuggers.

## Additional Notes

Would it be possible to add this enhancement in a future Ruby version?

Thank you for considering this request!




-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:121138] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
  2025-02-02  1:15 [ruby-core:120856] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number) ennder via ruby-core
                   ` (2 preceding siblings ...)
  2025-02-13 15:32 ` [ruby-core:120983] " mame (Yusuke Endoh) via ruby-core
@ 2025-02-21 18:37 ` ennder via ruby-core
  2025-02-25  9:49 ` [ruby-core:121156] " mame (Yusuke Endoh) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: ennder via ruby-core @ 2025-02-21 18:37 UTC (permalink / raw)
  To: ruby-core; +Cc: ennder

Issue #21105 has been updated by ennder (Jérôme BATAILLE).


Sorry to comment on a closed issue.

As a complement, I find it very useful when there is multiple objects calling the same method for exemple :

``` ruby
class Example
  def self.runnable?
    check_one.same_method_call? && check_two.same_method_call?
  end
end

Example.runnable?
```

``` ruby
# The position in the line helps to know which object is nil
trace.rb:4:46:in `runnable?': undefined method `same_method_call?' for nil:NilClass (NoMethodError)
```

Perhaps instead of the position we could have the name of the variable on which the call was done ? 

----------------------------------------
Feature #21105: Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
https://bugs.ruby-lang.org/issues/21105#change-112071

* Author: ennder (Jérôme BATAILLE)
* Status: Closed
----------------------------------------
## Subject

Improve Ruby Stack Trace to Include Exact Error Position (Column Number)

## Description

Currently, when an exception occurs in Ruby, the stack trace provides the file name and line number but does not indicate the exact position (column number) where the error occurred within the line. This lack of precision can make debugging more challenging, especially in cases where multiple method calls or expressions are present on the same line.

## Example

``` ruby
class Example
  def self.run
    nil.some_method_call  # Error occurs here
  end
end

Example.run
```

## Expected Behavior

The stack trace should include the column number where the error occurred, e.g.:

``` ruby
trace.rb:4:10:in `run': undefined method `some_method_call' for nil:NilClass (NoMethodError)
```


## Benefits

More precise debugging.

Easier identification of errors in complex one-liner expressions.

Better tooling support for editors and debuggers.

## Additional Notes

Would it be possible to add this enhancement in a future Ruby version?

Thank you for considering this request!




-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

* [ruby-core:121156] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
  2025-02-02  1:15 [ruby-core:120856] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number) ennder via ruby-core
                   ` (3 preceding siblings ...)
  2025-02-21 18:37 ` [ruby-core:121138] " ennder via ruby-core
@ 2025-02-25  9:49 ` mame (Yusuke Endoh) via ruby-core
  4 siblings, 0 replies; 6+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2025-02-25  9:49 UTC (permalink / raw)
  To: ruby-core; +Cc: mame (Yusuke Endoh)

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


@ennder Which Ruby version are you using? As @eregon said, a recent version of Ruby should show which error it was, as follows:

```
$ ruby trace.rb
trace.rb:3:in 'Example.runnable?': undefined method 'same_method_call?' for nil (NoMethodError)

    check_one.same_method_call? && check_two.same_method_call?
             ^^^^^^^^^^^^^^^^^^
        from trace.rb:14:in '<main>'
```

```
$ ruby trace.rb
trace.rb:3:in 'Example.runnable?': undefined method 'same_method_call?' for nil (NoMethodError)

    check_one.same_method_call? && check_two.same_method_call?
                                            ^^^^^^^^^^^^^^^^^^
        from trace.rb:14:in '<main>'
```


----------------------------------------
Feature #21105: Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
https://bugs.ruby-lang.org/issues/21105#change-112096

* Author: ennder (Jérôme BATAILLE)
* Status: Closed
----------------------------------------
## Subject

Improve Ruby Stack Trace to Include Exact Error Position (Column Number)

## Description

Currently, when an exception occurs in Ruby, the stack trace provides the file name and line number but does not indicate the exact position (column number) where the error occurred within the line. This lack of precision can make debugging more challenging, especially in cases where multiple method calls or expressions are present on the same line.

## Example

``` ruby
class Example
  def self.run
    nil.some_method_call  # Error occurs here
  end
end

Example.run
```

## Expected Behavior

The stack trace should include the column number where the error occurred, e.g.:

``` ruby
trace.rb:4:10:in `run': undefined method `some_method_call' for nil:NilClass (NoMethodError)
```


## Benefits

More precise debugging.

Easier identification of errors in complex one-liner expressions.

Better tooling support for editors and debuggers.

## Additional Notes

Would it be possible to add this enhancement in a future Ruby version?

Thank you for considering this request!




-- 
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/lists/ruby-core.ml.ruby-lang.org/

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

end of thread, other threads:[~2025-02-25  9:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-02  1:15 [ruby-core:120856] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number) ennder via ruby-core
2025-02-02 11:42 ` [ruby-core:120861] " Eregon (Benoit Daloze) via ruby-core
2025-02-13  7:30 ` [ruby-core:120969] " matz (Yukihiro Matsumoto) via ruby-core
2025-02-13 15:32 ` [ruby-core:120983] " mame (Yusuke Endoh) via ruby-core
2025-02-21 18:37 ` [ruby-core:121138] " ennder via ruby-core
2025-02-25  9:49 ` [ruby-core:121156] " mame (Yusuke Endoh) via ruby-core

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 NNTP newsgroup(s).