Syntax errors are concealed #31

Closed
mfn opened this Issue Mar 2, 2013 · 2 comments

Comments

Projects
None yet
3 participants

mfn commented Mar 2, 2013

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 added a commit that referenced this issue Mar 2, 2013

Collaborator

rking commented Mar 2, 2013

@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

rking added a commit that referenced this issue Mar 21, 2013

Owner

ConradIrwin commented Mar 21, 2013

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment