From c74d240d0af66f30ae50bec267a21d3572636618 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Thu, 12 Jan 2012 23:21:21 -0800 Subject: [PATCH] Don't clobber _ex_ on typoes --- lib/pry/pry_instance.rb | 7 ++++++- test/test_syntax_checking.rb | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index a036c914..4db7ad30 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -257,7 +257,12 @@ class Pry output.puts "Error: #{e.message}" end - break if complete_expression?(eval_string) + begin + break if complete_expression?(eval_string) + rescue SyntaxError => e + output.puts "SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}" + eval_string = "" + end end @suppress_output = true if eval_string =~ /;\Z/ || eval_string.empty? diff --git a/test/test_syntax_checking.rb b/test/test_syntax_checking.rb index b67e1539..f184816d 100644 --- a/test/test_syntax_checking.rb +++ b/test/test_syntax_checking.rb @@ -55,4 +55,9 @@ describe Pry do pry = Pry.new pry.complete_expression?("puts 1, 2,\n3").should == true end + + it "should not clobber _ex_ on a SyntaxError in the repl" do + + mock_pry("raise RuntimeError, 'foo';", "puts foo)", "_ex_.is_a?(RuntimeError)").should =~ /^RuntimeError.*\nSyntaxError.*\n=> true/m + end end