1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Be paranoid trying to output stuff.

If we don't do this, then pry can randomly exit because of a
serialization error (most usually undefined method #inspect).
This commit is contained in:
Conrad Irwin 2011-08-23 00:54:58 -07:00
parent f8b7260872
commit d007eff35c
2 changed files with 43 additions and 0 deletions

View file

@ -223,6 +223,19 @@ class Pry
else else
print.call output, result print.call output, result
end end
rescue Exception => e
# Being uber-paranoid here, given that this exception arose because we couldn't
# serialize something in the user's program, let's not assume we can serialize
# the exception either.
begin
output.puts "output error: #{e.inspect}"
rescue Exception => e
if last_result_is_exception?
output.puts "output error: failed to show exception"
else
output.puts "output error: failed to show result"
end
end
end end
# Returns true if input is "" and a command is not returning a # Returns true if input is "" and a command is not returning a

30
test/test_pry_output.rb Normal file
View file

@ -0,0 +1,30 @@
describe Pry do
describe "output failsafe" do
after do
Pry.config.print = Pry::DEFAULT_PRINT
end
it "should catch serialization exceptions" do
Pry.config.print = lambda { |*a| raise "catch-22" }
lambda {
mock_pry("1")
}.should.not.raise
end
it "should display serialization exceptions" do
Pry.config.print = lambda { |*a| raise "catch-22" }
mock_pry("1").should =~ /output error: #<RuntimeError: catch-22>/
end
it "should catch errors serializing exceptions" do
Pry.config.print = lambda do |*a|
raise Exception.new("catch-22").tap{ |e| class << e; def inspect; raise e; end; end }
end
mock_pry("1").should =~ /output error: failed to show result/
end
end
end