ConradIrwin / pry-rescue

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

try-again not working on newest master, error msg: "UncaughtThrowError: uncaught throw :try_again" #120

Closed zw963 closed 2 years ago

zw963 commented 3 years ago

Following is code example:

require 'pry-rescue'

def test
  raise "foo"
  # puts "foo"
rescue => e
  raise "bar"
end

binding.pry

Following is my gem version:

Fetching method_source-1.0.0.gem
Fetching interception-0.5.gem
Fetching pry-0.14.0.gem
Fetching pry-rescue-1.5.2.gem
Fetching coderay-1.1.3.gem
Successfully installed coderay-1.1.3
Successfully installed method_source-1.0.0
Successfully installed pry-0.14.0
Building native extensions. This could take a while...
Successfully installed interception-0.5
Successfully installed pry-rescue-1.5.2
5 gems installed

Following is reproduce:

From: /home/zw963/1.rb:11 :

     6: rescue => e
     7:   raise "bar"
     8: end
     9: 
    10: # pry!
 => 11: binding.pry

[1] pry(main)> test
RuntimeError: bar
from 1.rb:7:in `rescue in test'
Caused by RuntimeError: foo
from 1.rb:4:in `test'
[2] pry(main)> cd-cause

From: /home/zw963/1.rb:4 Object#test:

    3: def test
 => 4:   raise "foo"
    5:   # puts "foo"
    6: rescue => e
    7:   raise "bar"
    8: end

RuntimeError: foo
from 1.rb:4:in `test'
[1] pry(main)> edit -m
Waiting for Emacs...

From: /home/zw963/1.rb:10 :

     5:   puts "foo"
     6: rescue => e
     7:   raise "bar"
     8: end
     9: 
 => 10: binding.pry

[1] pry(main)> try-again
UncaughtThrowError: uncaught throw :try_again
from /home/zw963/others/.rvm/gems/ruby-2.7.1@rescue/gems/pry-rescue-1.5.2/lib/pry-rescue/commands.rb:74:in `throw'
[1] pry(main)>

Tested on both 2.7.1 and 3.0.0, thank you.

jurriaanschrofer commented 3 years ago

+1

jasonewall commented 2 years ago

Isn't your example missing wrapping the test call with Pry.rescue?

e.g.

Frame number: 0/0

From: /home/jason/Code/scratch/pry-rescue-test.rb:10 :

     5:   raise 'foo'
     6: rescue => e
     7:   raise 'bar'
     8: end
     9:
 => 10: binding.pry

[1] pry(main)> Pry.rescue { test }

Frame number: 0/18
Frame type: rescue

From: /home/jason/Code/scratch/pry-rescue-test.rb:7 Object#test:

    4: def test
    5:   raise 'foo'
    6: rescue => e
 => 7:   raise 'bar'
    8: end

RuntimeError: bar
from pry-rescue-test.rb:7:in `rescue in test'
Caused by RuntimeError: foo
from pry-rescue-test.rb:5:in `test'
[1] pry(main)> try-again

Frame number: 0/18
Frame type: rescue

From: /home/jason/Code/scratch/pry-rescue-test.rb:7 Object#test:

    4: def test
    5:   raise 'foo'
    6: rescue => e
 => 7:   raise 'bar'
    8: end

RuntimeError: bar
from pry-rescue-test.rb:7:in `rescue in test'
Caused by RuntimeError: foo
from pry-rescue-test.rb:5:in `test'
[1] pry(main)>
zw963 commented 2 years ago

Yes, you are right, thank you.