Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing spaces/punctuation in SyntaxError message. #225

Closed
sanjioh opened this issue Oct 14, 2024 · 3 comments · Fixed by #232
Closed

Missing spaces/punctuation in SyntaxError message. #225

sanjioh opened this issue Oct 14, 2024 · 3 comments · Fixed by #232

Comments

@sanjioh
Copy link

sanjioh commented Oct 14, 2024

Hi all,

with the following simple snippet of Ruby code:

def x.y.z
end

the interpreter raises a SyntaxError, whose message is made up of two sentences with no spaces or punctuation in between (see line no. 2 of the output):

scratch2.rb: --> scratch2.rb
expected a delimiter to close the parametersunexpected '.', ignoring it
> 1  def x.y.z
> 2  end

scratch2.rb:1: syntax errors found (SyntaxError)
> 1 | def x.y.z
    |        ^ unexpected '.', ignoring it
    |        ^ expected a delimiter to close the parameters
  2 | end
  3 |

This happens on Ruby master with the sentences reported above, but also on 3.3.5 with the sentences:
expected a delimiter to close the parameterscannot parse the expression.
In both cases, gem list returns syntax_suggest (default: 2.0.0).

Unfortunately I can't tell if the same glitch occurs with other error messages.

Thanks!

schneems added a commit that referenced this issue Nov 15, 2024
In #225 it was reported that the output looks incorrect:

```
$ cat /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
def x.y.z
end
$ ruby /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
/tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb: --> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
expected a delimiter to close the parametersunexpected '.', ignoring it
> 1  def x.y.z
> 2  end
```

Specifically:

```
expected a delimiter to close the parametersunexpected '.', ignoring it
```

However this does not show up when executing the debug executable:

```
$ bin/bundle exec exe/syntax_suggest /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
--> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb

expected a delimiter to close the parameters
unexpected '.', ignoring it

> 1  def x.y.z
> 2  end
```

This is because `exe/syntax_suggest` uses STDOUT.puts while calling `ruby` with the filename uses a fake IO object represented by MiniStringIO. This class was incorrectly not adding a newline to the end of the print.

The fix was to move the class to it's own file where it can be tested and then fix the behavior.

close #225

Co-authored-by: Andy Yong <andyywz@gmail.com>
schneems added a commit that referenced this issue Nov 15, 2024
In #225 it was reported that the output looks incorrect:

```
$ cat /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
def x.y.z
end
$ ruby /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
/tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb: --> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
expected a delimiter to close the parametersunexpected '.', ignoring it
> 1  def x.y.z
> 2  end
```

Specifically:

```
expected a delimiter to close the parametersunexpected '.', ignoring it
```

However this does not show up when executing the debug executable:

```
$ bin/bundle exec exe/syntax_suggest /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
--> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb

expected a delimiter to close the parameters
unexpected '.', ignoring it

> 1  def x.y.z
> 2  end
```

This is because `exe/syntax_suggest` uses STDOUT.puts while calling `ruby` with the filename uses a fake IO object represented by MiniStringIO. This class was incorrectly not adding a newline to the end of the print.

The fix was to move the class to it's own file where it can be tested and then fix the behavior.

close #225

Co-authored-by: Andy Yong <andyywz@gmail.com>
matzbot pushed a commit to ruby/ruby that referenced this issue Nov 15, 2024
In #225 it was reported that the output looks incorrect:

```
$ cat /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
def x.y.z
end
$ ruby /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
/tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb: --> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
expected a delimiter to close the parametersunexpected '.', ignoring it
> 1  def x.y.z
> 2  end
```

Specifically:

```
expected a delimiter to close the parametersunexpected '.', ignoring it
```

However this does not show up when executing the debug executable:

```
$ bin/bundle exec exe/syntax_suggest /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb
--> /tmp/4a71c7e417cc9eac0971e3a2519b295c/scratch.rb

expected a delimiter to close the parameters
unexpected '.', ignoring it

> 1  def x.y.z
> 2  end
```

This is because `exe/syntax_suggest` uses STDOUT.puts while calling `ruby` with the filename uses a fake IO object represented by MiniStringIO. This class was incorrectly not adding a newline to the end of the print.

The fix was to move the class to it's own file where it can be tested and then fix the behavior.

close ruby/syntax_suggest#225

ruby/syntax_suggest@d2ecd94a3b

Co-authored-by: Andy Yong <andyywz@gmail.com>
@schneems
Copy link
Collaborator

Thanks for the report. This is fixed in 2.0.2

@sanjioh
Copy link
Author

sanjioh commented Nov 15, 2024

Thank you for the fix!

@mtasaka
Copy link

mtasaka commented Nov 17, 2024

Now this is causing rspec-core side test failure, not sure which side should fix: rspec/rspec-core#3125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants