Issue #10982 has been updated by olivierlacan (Olivier Lacan).


I just ran into a `SyntaxError` on heapy today (in Ruby 2.1.6) and it did exactly what I wish would occur for `NoMethodError`: 

```
$ heapy read ruby-heap-2018-07-24\ 01\:29\:05.dump
/Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': /Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/heapy-0.1.3/lib/heapy/alive.rb:133: syntax error, unexpected '.' (SyntaxError)
...lf.address_to_object(address)&.inspect || "object not traced...
...                               ^
	from /Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/heapy-0.1.3/lib/heapy.rb:69:in `<top (required)>'
	from /Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:127:in `require'
	from /Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:127:in `rescue in require'
	from /Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:40:in `require'
	from /Users/olivierlacan/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/heapy-0.1.3/bin/heapy:4:in `<top (required)>'
	from /Users/olivierlacan/.rbenv/versions/2.1.6/bin/heapy:22:in `load'
	from /Users/olivierlacan/.rbenv/versions/2.1.6/bin/heapy:22:in `<main>'
```

If we can do this for `SyntaxError`, I don't see why we shouldn't do it for `NotMethodError` as well. Is anyone familiar with how the SyntaxError feedback is generated?

----------------------------------------
Feature #10982: Clarify location of NoMethod error
https://bugs.ruby-lang.org/issues/10982#change-73087

* Author: schneems (Richard Schneeman)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
In Ruby, the error `NoMethodError` on happens frequently, especially when it occurs on `nil`. This error can be confusing to beginners since, many of them think there is a problem with the method instead of the receiver. This error can be confusing to advanced developers when there are multiple method calls in the on the same line. In this example it is unclear if `foo` or `bar` returned `nil`:

```
foo.call && bar.call
NoMethodError: undefined method `call' for nil:NilClass
```

I would like to make this a better error message and to indicate where the exception occurs.

```
@foo.call && @bar.call
                 ^----
NoMethodError: The method `call` is undefined on receiver nil:NilClass
```

Now it is more clear that the `@bar` is currently `nil` and that is the source of the error. I believe exposing this information will help developers of all abilities. 




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>