Skip to content

Commit

Permalink
added error handling to cat command
Browse files Browse the repository at this point in the history
  • Loading branch information
banister committed Sep 15, 2011
1 parent 3549cc1 commit f89f31f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -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

Expand Down
Empty file modified bin/pry 100644 → 100755
Empty file.
11 changes: 8 additions & 3 deletions lib/pry/default_commands/shell.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/test_default_commands/test_shell.rb
Expand Up @@ -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
Expand Down

0 comments on commit f89f31f

Please sign in to comment.