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

added error handling to cat command

This commit is contained in:
John Mair 2011-09-14 23:35:08 +12:00
parent 3549cc108b
commit f89f31ff49
4 changed files with 15 additions and 3 deletions

View file

@ -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

0
bin/pry Normal file → Executable file
View file

View file

@ -92,8 +92,13 @@ class Pry
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 @@ class Pry
# 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)

View file

@ -3,6 +3,12 @@ require 'helper'
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