From 76d1c4ff70d40e3480e66fdb18b38a50f2a47b21 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Sat, 10 Sep 2011 12:52:05 -0700 Subject: [PATCH] Don't explode if the file we're in doesn't exist. This happens particularly in testing where you want to delete files after each test, but the REPL state isn't reset correctly. --- lib/pry/default_commands/context.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/pry/default_commands/context.rb b/lib/pry/default_commands/context.rb index 8b9fb434..52f3d4f1 100644 --- a/lib/pry/default_commands/context.rb +++ b/lib/pry/default_commands/context.rb @@ -147,6 +147,10 @@ class Pry set_file_and_dir_locals(file) output.puts "\n#{text.bold('From:')} #{file} @ line #{line_num} in #{klass}##{meth_name}:\n\n" + unless File.readable?(file) + output.puts "Cannot open #{file.inspect} for reading." + next + end # This method inspired by http://rubygems.org/gems/ir_b File.open(file).each_with_index do |line, index|