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

The error message of SyntaxError is different from Ruby's one #2102

Closed
ttanimichi opened this issue Feb 17, 2020 · 1 comment
Closed

The error message of SyntaxError is different from Ruby's one #2102

ttanimichi opened this issue Feb 17, 2020 · 1 comment

Comments

@ttanimichi
Copy link

The error message of ruby -e and irb contains unexpected => but pry's one doesn't.

$ ruby -e 'puts {"gender"=>"female"}.to_json'
-e:1: syntax error, unexpected =>, expecting '}'
puts {"gender"=>"female"}.to_json
-e:1: syntax error, unexpected '}', expecting end-of-input
puts {"gender"=>"female"}.to_json
$ pry
[1] pry(main)> puts {"gender"=>"female"}.to_json
SyntaxError: unexpected '}', expecting end-of-input
puts {"gender"=>"female"}.to_json
                        ^
$ irb
irb(main):001:0> puts {"gender"=>"female"}.to_json
Traceback (most recent call last):
        3: from /Users/tsukuru.tanimichi/.rbenv/versions/2.6.5/bin/irb:23:in `<main>'
        2: from /Users/tsukuru.tanimichi/.rbenv/versions/2.6.5/bin/irb:23:in `load'
        1: from /Users/tsukuru.tanimichi/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
SyntaxError ((irb):1: syntax error, unexpected =>, expecting '}')
puts {"gender"=>"female"}.to_json
              ^~
(irb):1: syntax error, unexpected '}', expecting end-of-input
puts {"gender"=>"female"}.to_json
                        ^

environment

$ ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]

$ pry -v
Pry version 0.12.2 on Ruby 2.6.5
barrettkingram pushed a commit to barrettkingram/pry that referenced this issue Mar 21, 2020
Previously when catching syntax errors in the REPL, we were only showing
the last syntax error displayed by the ruby output. However, ruby can
generate multiple syntax error messages within a single SyntaxException.
For example, this code generates multiple syntax error messages:
```
$ ruby -e 'puts {"key"=>"val"}.to_json'
-e:1: syntax error, unexpected =>, expecting '}'
puts {"key"=>"val"}.to_json
-e:1: syntax error, unexpected '}', expecting end-of-input
puts {"key"=>"val"}.to_json
```
We can't predict which error message would be most helpful for the
consumer - we should show both of them.

This commit modifies the string replacement we're doing when printing
SyntaxExceptions so any number of syntax error lines will be shown
correctly.

Issue: pry#2102
The error message of SyntaxError is different from Ruby's one
barrettkingram pushed a commit to barrettkingram/pry that referenced this issue Mar 21, 2020
Previously when catching syntax errors in the REPL, we were only showing
the last syntax error displayed by the ruby output. However, ruby can
generate multiple syntax error messages within a single SyntaxException.
For example, this code generates multiple syntax error messages:
```
$ ruby -e 'puts {"key"=>"val"}.to_json'
-e:1: syntax error, unexpected =>, expecting '}'
puts {"key"=>"val"}.to_json
-e:1: syntax error, unexpected '}', expecting end-of-input
puts {"key"=>"val"}.to_json
```
We can't predict which error message would be most helpful for the
consumer - we should show both of them.

This commit modifies the string replacement we're doing when printing
SyntaxExceptions so any number of syntax error lines will be shown
correctly.

Issue: pry#2102
The error message of SyntaxError is different from Ruby's one
@barrettkingram
Copy link
Contributor

Looks like if a statement causes multiple syntax error lines in the error message, Pry is only displaying the last one. I've attempted a fix for the issue: #2117

@kyrylo kyrylo closed this as completed Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants