diff options
author | Barrett Ingram <bingram@eab.com> | 2020-03-21 10:53:27 -0500 |
---|---|---|
committer | Barrett Ingram <bingram@eab.com> | 2020-03-21 11:17:27 -0500 |
commit | f6736d526260b2aa9f50b61150a67fcfa2045893 (patch) | |
tree | 824683180ee5da0ab33f8bc4698d358097bd53f3 /lib | |
parent | 2208ed30f246b4dbeb512745021e00052781ece6 (diff) | |
download | pry-f6736d526260b2aa9f50b61150a67fcfa2045893.tar.gz |
Display all syntax error messages when catching SyntaxException
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: https://github.com/pry/pry/issues/2102
The error message of SyntaxError is different from Ruby's one
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pry/pry_instance.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 9ccca364..d1de5c4d 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -627,7 +627,7 @@ class Pry begin complete_expr = Pry::Code.complete_expression?(@eval_string) rescue SyntaxError => e - output.puts "SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}" + output.puts e.message.gsub(/^.*syntax error, */, "SyntaxError: ") reset_eval_string end |