ConradIrwin / pry-rescue

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

Syntax errors are concealed #31

Closed mfn closed 11 years ago

mfn commented 11 years ago

Running rescue on a script with an syntax error conceals the real error:

$ cat script.rb 
def
$ ruby -c script.rb                                                                                                
script.rb:1: syntax error, unexpected $end
$ rescue script.rb 
/data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue.rb:169:in `+': can't convert nil into Array (TypeError)
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue.rb:169:in `without_duplicates'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue.rb:54:in `enter_exception_context'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue/core_ext.rb:38:in `rescued'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue/core_ext.rb:18:in `rescue in block (2 levels) in rescue'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue/core_ext.rb:15:in `block (2 levels) in rescue'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue/core_ext.rb:13:in `catch'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue/core_ext.rb:13:in `block in rescue'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue/core_ext.rb:12:in `loop'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue/core_ext.rb:12:in `rescue'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/lib/pry-rescue.rb:72:in `load'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/gems/pry-rescue-1.0.0/bin/rescue:42:in `<top (required)>'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/bin/rescue:19:in `load'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/bin/rescue:19:in `<main>'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
        from /data/users/mfn/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'

A simple workaround at the shell level is easily possible: ruby -c script.rb && rescue script.rb.

But maybe there's also a nice way to make rescue more robust in this regard.

rking commented 11 years ago

@ConradIrwin - I didn't finish this, because I'm barely propping up my eyelids. It's maybe a start?: https://github.com/ConradIrwin/pry-rescue/tree/handle-syntax-errors

ConradIrwin commented 11 years ago

This should now open a pry console just like any other error, please let me know if you're still having difficulties.