ConradIrwin / pry-rescue

Start a pry session whenever something goes wrong.
MIT License
852 stars 49 forks source link

Problems running rescue on files with syntax errors #57

Closed vincentwoo closed 10 years ago

vincentwoo commented 10 years ago

pry-rescue's stacktrace and binding seem to be in the wrong place when the script in question has a syntax error:

root@a6e90db5182b:~# cat test.rb
y = 1
x = 2,
root@a6e90db5182b:~# rescue test.rb

From: /usr/local/lib/ruby/gems/2.0.0/gems/pry-rescue-1.3.1/lib/pry-rescue.rb @ line 70 PryRescue.load:

    69: def load(script)
 => 70:   Pry::rescue{ Kernel.load script }
    71: end

SyntaxError: /home/coderpad/test.rb:2: syntax error, unexpected end-of-input
from /usr/local/lib/ruby/gems/2.0.0/gems/pry-rescue-1.3.1/lib/pry-rescue.rb:70:in `load'
[1] 2.0.0~@&x
NameError: undefined local variable or method `x' for PryRescue:Class
from (pry):1:in `block in load'
[2] 2.0.0~@&y
NameError: undefined local variable or method `y' for PryRescue:Class
from (pry):2:in `block in load'
[3] 2.0.0~@&
kyrylo commented 10 years ago

On Ruby ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux] I get slightly different output.

% rescue foo.rb                                                                                                                                                                                   
/home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue.rb:154:in `without_bindings_below_raise': undefined method `size' for nil:NilClass (NoMethodError)
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue.rb:51:in `enter_exception_context'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue/core_ext.rb:37:in `rescued'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue/core_ext.rb:17:in `rescue in block (2 levels) in rescue'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue/core_ext.rb:14:in `block (2 levels) in rescue'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue/core_ext.rb:13:in `catch'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue/core_ext.rb:13:in `block in rescue'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue/core_ext.rb:12:in `loop'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue/core_ext.rb:12:in `rescue'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/lib/pry-rescue.rb:70:in `load'
        from /home/kyrylo/.gem/ruby/2.1.0/gems/pry-rescue-1.3.1/bin/rescue:42:in `<top (required)>'
        from /home/kyrylo/.gem/ruby/2.1.0/bin/rescue:23:in `load'
        from /home/kyrylo/.gem/ruby/2.1.0/bin/rescue:23:in `<main>'