ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: shevegen@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:84502] [Ruby trunk Feature#14244] Better error messages for scripts with non-matching end statements
Date: Wed, 27 Dec 2017 10:28:54 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-69027.20171227102853.439fa85454a8525e@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-14244.20171227011618@ruby-lang.org

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 Dürst)
* 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/

  parent reply	other threads:[~2017-12-27 10:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-14244.20171227011618@ruby-lang.org>
2017-12-27  1:16 ` [ruby-core:84491] [Ruby trunk Feature#14244] Better messages for scripts with non-matching end statements duerst
2017-12-27 10:28 ` shevegen [this message]
2017-12-27 13:14 ` [ruby-core:84513] [Ruby trunk Feature#14244] Better error " mame
2018-11-29  1:08 ` [ruby-core:90146] " foonlyboy
2018-11-29  3:52 ` [ruby-core:90148] " mame
2018-11-29  8:57 ` [ruby-core:90158] " duerst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-69027.20171227102853.439fa85454a8525e@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).