Issue #14244 has been updated by shevegen (Robert A. Heiler).


Would be nice.

My current "strategy" is to make mostly small changes and see what/if anything breaks.
This is not very sophisticated but it works, sort of.

Reminds me of tenderlove's blog entry about being a puts-debugger; in my case I
am a pp-debugger, aka using pp ... and really just the simplest way to find
problems ... :P

That's also why I liked the did-you-mean gem since it is simple but effective.

While I personally think that I do not ultimately need better problem-reporting
in regards to missing or erroneous end statements, newcomers to ruby may
definitely benefit from this, so +1.

It may also fit to the philosophy of focusing on the human side of programming.

----------------------------------------
Feature #14244: Better error messages for scripts with non-matching end statements
https://bugs.ruby-lang.org/issues/14244#change-69027

* Author: duerst (Martin Drst)
* Status: Open
* Priority: Normal
* Assignee: mame (Yusuke Endoh)
* Target version: 
----------------------------------------
At the party at Speee yesterday, @mame explained that one of his contributions to Ruby 2.5 was to make available information about on which lines code blocks would start and end.

This reminded me of one (actually two) of what I think are the most unhelpful error messages from Ruby:

`syntax error, unexpected end-of-input, expecting keyword_end`
and
`syntax error, unexpected keyword_end, expecting end-of-input`

These two messages are unhelpful because they get created at the end of the input when the problem is often somewhere in the middle of a long program. They are a problem both for beginners (who often encounter them without knowing what to fix) and experts (for whom better error messages could lead to productivity gains).

I discussed this at the party with Yusuke and @naruse, which led to the following additional information:

- A strategy I use when I get such an error message is to randomly insert/delete some `end` in my program and move it
  around until I find the correct place for it (with something like binary search). Anything faster would be better.
- Using `-w` can produce additional output. Trying this out today, I got a message for a missing `end` keyword,
  but not for a superfluous `end` keyword. (Of course, a better error message would be desirable for both cases.)

```
duerst@Arnisee /cygdrive/c/tmp
$ ruby missing_ends.rb
missing_ends.rb:9: syntax error, unexpected end-of-input, expecting keyword_end

duerst@Arnisee /cygdrive/c/tmp
$ ruby -w missing_ends.rb
missing_ends.rb:9: warning: mismatched indentations at 'end' with 'def' at 2
missing_ends.rb:9: syntax error, unexpected end-of-input, expecting keyword_end
```

[different program]

```
duerst@Arnisee /cygdrive/c/tmp
$ ruby missing_ends.rb
missing_ends.rb:10: syntax error, unexpected keyword_end, expecting end-of-input

duerst@Arnisee /cygdrive/c/tmp
$ ruby -w missing_ends.rb
missing_ends.rb:10: syntax error, unexpected keyword_end, expecting end-of-input
```

- One strategy to produce better error messages might be to re-read the input with -w on,
  but that's difficult because the input may not be a file.
- The information that Yusuke made available is part of the syntax tree, which isn't
  really available when there's a syntax error, but it might be possible to reuse
  partially generated syntax tree fragments. @nobu might be able to do this.

I have assigned this issue to @mame because he may know best what to do next. Please feel free to reassign it to somebody else.



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