Skip to content

Instantly share code, notes, and snippets.

@ConradIrwin

ConradIrwin/a.rb Secret

Created December 6, 2012 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ConradIrwin/8992b265c63ff966d0d3 to your computer and use it in GitHub Desktop.
Save ConradIrwin/8992b265c63ff966d0d3 to your computer and use it in GitHub Desktop.
diff --git a/lib/pry.rb b/lib/pry.rb
index 718e3e4..c2e030b 100644
--- a/lib/pry.rb
+++ b/lib/pry.rb
@@ -65,9 +65,15 @@ class Pry
end
# Will only show the first line of the backtrace
- DEFAULT_EXCEPTION_HANDLER = proc do |output, exception, _|
- output.puts "#{exception.class}: #{exception.message}"
- output.puts "from #{exception.backtrace.first}"
+ DEFAULT_EXCEPTION_HANDLER = proc do |output, exception, _pry_|
+ if exception.equal? _pry_.result
+ output.puts "#{exception.class}: #{exception.message}"
+ output.puts "from #{exception.backtrace.first}"
+ elsif SyntaxError == exception
+ output.puts "SyntaxError: #{exception.message}"
+ else
+ output.puts "Error: #{exception.message}"
+ end
end
DEFAULT_PROMPT_NAME = 'pry'
diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb
index 21b3acb..1ef55c5 100644
--- a/lib/pry/pry_instance.rb
+++ b/lib/pry/pry_instance.rb
@@ -300,13 +300,13 @@ class Pry
# eval_string will probably be mutated by this method
retrieve_line(eval_string, target)
rescue CommandError, Slop::InvalidOptionError, MethodSource::SourceNotFoundError => e
- output.puts "Error: #{e.message}"
+ exception_handler.call(output, e, self)
end
begin
break if Pry::Code.complete_expression?(eval_string)
rescue SyntaxError => e
- output.puts "SyntaxError: #{e.message.sub(/.*syntax error, */m, '')}"
+ exception_handler.call(output, e, self)
eval_string = ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment