[ruby-core:120983] [Ruby master Feature#21105] Improve Ruby Stack Trace to Include Exact Error Position (Column Number)
From:
"mame (Yusuke Endoh) via ruby-core" <ruby-core@...>
Date:
2025-02-13 15:32:02 UTC
List:
ruby-core #120983
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 j=
umpto that location.
However, there are numerous problems to making this happen.
* Which specific column position should be displayed: For NoMethodError, ne=
ar the beginning of the method name seems appropriate. However, for Argumen=
tError, you may want to indicate the position of the argument that caused t=
he 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, no=
t the column information. We need to store column information for each byte=
code instruction, which will require memory overhead, or, to reopen and rep=
arse 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 caus=
e that parsing to stop working.
----------------------------------------
Feature #21105: Improve Ruby Stack Trace to Include Exact Error Position (C=
olumn Number)
https://bugs.ruby-lang.org/issues/21105#change-111885
* Author: ennder (J=E9r=F4me 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 f=
ile name and line number but does not indicate the exact position (column n=
umber) 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:NilClas=
s (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!
--=20
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.rub=
y-lang.org/