Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pry-Rescue stops on enter_exception_context instead of the actual error #124

Open
Pifoupif opened this issue Aug 31, 2022 · 4 comments
Open

Comments

@Pifoupif
Copy link

Pifoupif commented Aug 31, 2022

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 the enter_exception_context rather than on the error itself:

image

Any idea how to fix this ?

@Pifoupif Pifoupif changed the title Pry-Rescue stops on enter_exception_context instead of the actual error Pry-Rescue stops on enter_exception_context instead of the actual error Aug 31, 2022
@yann120
Copy link

yann120 commented Sep 2, 2022

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 :

  • pry from 0.13.1 to 0.14.1
  • pry-byebug from 3.9.0 to 3.10.0

@StefanoMartin
Copy link

StefanoMartin commented Apr 19, 2023

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.

afn added a commit to cygnuseducation/pry-byebug that referenced this issue Sep 21, 2023
See ConradIrwin/pry-rescue#124 --- pry-byebug
doesn't play nicely with pry-rescue. Detect if we're in a rescued
exception, and if so, use pry without byebug.
@afn
Copy link
Contributor

afn commented Sep 22, 2023

See deivid-rodriguez/pry-byebug#422 --- this disables byebug when pry is invoked by pry-rescue.

Gemfile:

gem 'pry-byebug', github: 'cygnuseducation/pry-byebug'

@idrozd
Copy link

idrozd commented May 17, 2024

@afn jesus, thanks! Finally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants