Permalink
Browse files

added error handling to cat command

  • Loading branch information...
1 parent 3549cc1 commit f89f31ff4926b24f9440e19b7ee289fd37119a22 @banister banister committed Sep 14, 2011
Showing with 15 additions and 3 deletions.
  1. +1 −0 CHANGELOG
  2. 0 bin/pry
  3. +8 −3 lib/pry/default_commands/shell.rb
  4. +6 −0 test/test_default_commands/test_shell.rb
View
@@ -12,6 +12,7 @@
* added "unindent" helper to make adding help to commands easier
* local ./.pryrc now loaded after ~/.pryrc if it exists
* cat --ex N and edit --ex N now can navigate through backtrace, where cat --ex (with no args) moves throuh successive levels of the backtrace automatically with state stored on the exceptino object itself
+* new option Pry.config.exception_window_size determines window size for cat --ex
8/9/2011 version 0.9.5
View
0 bin/pry 100644 → 100755
No changes.
@@ -92,8 +92,13 @@ module DefaultCommands
next
end
- contents, _, _ = read_between_the_lines(file_name, start_line, end_line)
- contents = syntax_highlight_by_file_type_or_specified(contents, file_name, opts[:type])
+ begin
+ contents, _, _ = read_between_the_lines(file_name, start_line, end_line)
+ contents = syntax_highlight_by_file_type_or_specified(contents, file_name, opts[:type])
+ rescue Errno::ENOENT
+ output.puts "Could not find file: #{file_name}"
+ next
+ end
if opts.l?
contents = text.with_line_numbers contents, start_line + 1
@@ -115,7 +120,7 @@ module DefaultCommands
# header for exceptions
output.puts "\n#{Pry::Helpers::Text.bold('Exception:')} #{_pry_.last_exception.class}: #{_pry_.last_exception.message}\n--"
- output.puts "#{Pry::Helpers::Text.bold('From:')} #{ex_file} @ line #{ex_line} @ #{text.bold('level: ')} #{bt_index} of backtrace.\n\n"
+ output.puts "#{Pry::Helpers::Text.bold('From:')} #{ex_file} @ line #{ex_line} @ #{text.bold('level: ')} #{bt_index} of backtrace (of #{_pry_.last_exception.backtrace.size - 1}).\n\n"
end
set_file_and_dir_locals(file_name)
@@ -3,6 +3,12 @@
describe "Pry::DefaultCommands::Shell" do
describe "cat" do
+ describe "on receiving a file that does not exist" do
+ it 'should display an error message' do
+ mock_pry("cat supercalifragilicious66").should =~ /Could not find file/
+ end
+ end
+
# this doesnt work so well on rbx due to differences in backtrace
# so we currently skip rbx until we figure out a workaround
describe "with --ex" do

0 comments on commit f89f31f

Please sign in to comment.