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


parkr (Parker M) wrote:
> This new syntax is a pretty sizable divergence from traditional Ruby error reporting. 
Yes, and I would consider that a good thing.

> At the moment, errors generally (always?) have an accompanying stack trace:

I don't think this suggestion implies removing the stack trace, which is still valuable context.

> It indicates the line, but excludes the column. It's uniform for all errors, so users seeing these stack traces know in what file, what line, and what method (the binding?) the error occurred.

There's no reason we can't work incrementally and slowly improve each major error class to include clearer indications as to what particular portion of a line caused an error.

> If the proposed format were implemented, would it only be for NoMethodError's, or would it apply to ArgumentError's or TypeError's, and so on?
> 
> Would the column number suffice? So your example would yield:

Do you often identify pieces of a line of code by column number or based on the actual code keywords? I'm not trying to be snarky, but columns are for machine and text editors, not humans. This wouldn't be very consistent with Ruby's focus on programmer-friendliness to do half the work (find the column) and let programmers do the rest.

shevegen (Robert A. Heiler) wrote: 
> I think ruby warnings do not start with capitalized character such as in "The" :)

Agreed. `method 'call' is undefined on receiver nil:NilClass` makes more sense and to me is more legible than the current `undefined method 'call' for nil:NilClass`.

yuki24 (Yuki Nishijima) wrote: 

> It wasn't so hard to implement this in pure Ruby, the last example doesn't work, though.

Thank you so much for writing this proof of concept. 

The last example works fine for me though: 

```
irb(main):043:0> @foo = nil
=> nil
irb(main):044:0> @bar = nil
=> nil
irb(main):045:0> @foo.call && @bar.call
NoMethodError: undefined method `call' for nil:NilClass

  @foo.call && @bar.call
                   ^ĦħĦħĦħĦħ

	from (irb):45
	from /Users/olivierlacan/.rbenv/versions/2.4.0/bin/irb:11:in `<main>'
```



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

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