Open Pifoupif opened 2 years ago
I confirm that we are experiencing exactly the same issue on our side since few weeks... I think the breaking change is since our gem upgrade :
I want to confirm that the error is still present and it occurs when pry-byebug 3.10.1 is used together with pry-rescue.
Working example:
require 'pry-rescue'
def test
raise "foo"
rescue => e
raise "bar"
end
Pry.rescue do
test
end
Work as expected:
Frame number: 0/6
Frame type: rescue
From: /home/user/testrescue.rb:6 Object#test:
3: def test
4: raise "foo"
5: rescue => e
=> 6: raise "bar"
7: end
RuntimeError: bar
from testrescue.rb:6:in `rescue in test'
Caused by RuntimeError: foo
from testrescue.rb:4:in `test'
Bad example:
require 'pry-rescue'
require "pry-byebug"
def test
raise "foo"
rescue => e
raise "bar"
end
Pry.rescue do
test
end
It does not work as expected:
Frame number: 0/23
From: /usr/share/rvm/gems/ruby-3.2.2/gems/pry-rescue-1.5.2/lib/pry-rescue.rb:65 PryRescue.enter_exception_context:
46: def enter_exception_context(exception)
47: @any_exception_captured = true
48: @exception_context_depth ||= 0
49: @exception_context_depth += 1
50:
51: exception = exception.instance_variable_get(:@rescue_cause) if phantom_load_raise?(exception)
52: bindings = exception.instance_variable_get(:@rescue_bindings)
53:
54: bindings = without_bindings_below_raise(bindings)
55: bindings = without_duplicates(bindings)
56:
57: with_program_name "#$PROGRAM_NAME [in pry-rescue @ #{Dir.pwd}]" do
58: if defined?(PryStackExplorer)
59: pry :call_stack => bindings,
60: :hooks => pry_hooks(exception),
61: :initial_frame => initial_frame(bindings)
62: else
63: Pry.start bindings.first, :hooks => pry_hooks(exception)
64: end
=> 65: end
66: ensure
67: @exception_context_depth -= 1
68: end
This is quite an issue because both the libraries (pry-rescue and pry-byebug) are important, and downgrade is not possible since the old version of bye-prybug does not support Ruby 3.2.
See https://github.com/deivid-rodriguez/pry-byebug/pull/422 --- this disables byebug when pry is invoked by pry-rescue.
Gemfile:
gem 'pry-byebug', github: 'cygnuseducation/pry-byebug'
@afn jesus, thanks! Finally
We have upgraded our stack recently and are now on rails 7.0.0 and ruby 3.1.1.
Since then when I run :
PRY_RESCUE_RAILS=1 bundle exec rails test test/controllers/...
(or every other ways of launching my test with pry-rescue) the context is stopped in theenter_exception_context
rather than on the error itself:Any idea how to fix this ?