pry-byebug icon indicating copy to clipboard operation
pry-byebug copied to clipboard

Newest version of Pry breaks pry-byebug

Open thomaswuensche opened this issue 4 years ago • 12 comments

The Pull Request pry/pry#2119 from November changed the way plugins are loaded in Pry: they're no longer autoloaded and need to be required in .pryrc.

However, this does not work for me with pry-byebug.

Steps to reproduce:

  • clone 'pry' and 'pry-byebug'
  • build and install gems
  • add require 'pry-byebug' to .pryrc
  • run a ruby test file with require 'pry'; binding.pry included
  • type next into Pry

Expected behaviour: Pry executes the next line.

Observed behaviour: Pry crashes. Stacktrace:

[1] pry(main)> next
UncaughtThrowError: uncaught throw :breakout_nav
from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-byebug-3.9.0/lib/pry-byebug/helpers/navigation.rb:15:in `throw'
Traceback (most recent call last):
	12: from test.rb:3:in `<main>'
	11: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/core_extensions.rb:45:in `pry'
	10: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_class.rb:188:in `start'
	 9: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:15:in `start'
	 8: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `start'
	 7: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:78:in `with_ownership'
	 6: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:61:in `__with_ownership'
	 5: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `block in start'
	 4: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `repl'
	 3: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `loop'
	 2: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:68:in `block in repl'
	 1: from /Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:95:in `read'
/Users/thomas/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:454:in `select_prompt': private method `eval' called for nil:NilClass (NoMethodError)

Investigation: I believe this is the case because pry-byebug needs to be required before Pry.start is executed so that https://github.com/deivid-rodriguez/pry-byebug/blob/34ba6766d998d934169cd5e4887da2b69a884cde/lib/pry-byebug/pry_ext.rb#L17 applies. This was previously achieved because prior to executing Pry.start and actually loading the plugins, Pry would load the cli options through Pry::CLI.add_plugin_options. Since lib/pry-byebug/cli.rb loaded everything, this worked.

This has now changed because you need to require pry-byebug in your .pryrc and Pry.load_rc_files is executed after Pry.start.

As a hacky fix, Pry.load_rc_files can be added to pry/lib/pry.rb. This will load .pryrc and therefore require pry-byebug before Pry is started.

Questions:

  • @mvz mentioned in his PR that he successfully tested the new plugin loading with pry-byebug. Is this an error on my side, am i missing sth here?
  • Can this be fixed by changing pry-byebug or does this actually need to be adressed in Pry's code?

thomaswuensche avatar Jan 16 '21 01:01 thomaswuensche

I can reproduce this. It seems my testing was lousy. I apologize.

mvz avatar Jan 16 '21 08:01 mvz

Can this be solved with an extend instead of monkey-patching?

kyrylo avatar Feb 16 '21 08:02 kyrylo

Sorry for the delay here, I'll try to allocate some time soon to have a look. But yeah, it'd be great to find a solution that doesn't involve monkey-patching!

deivid-rodriguez avatar Feb 16 '21 10:02 deivid-rodriguez

I'd be interested if you wanted to test the 'opt-in' plugin behavior in https://github.com/pry/pry/pull/2177 since I didn't find much of a way to test it on my own

bf4 avatar Feb 16 '21 22:02 bf4

Same problem in Pry 0.14.1 how can i resolve this problem??

sphynx79 avatar Apr 13 '21 09:04 sphynx79

Despite having locked pry to 0.13.0, pry-byebug still gives me the UncaughtThrowError: uncaught throw :breakout_nav error.

@thomaswuensche said:

As a hacky fix, Pry.load_rc_files can be added to pry/lib/pry.rb. This will load .pryrc and therefore require pry-byebug before Pry is started.

Where would I add this? I'm greatly missing pry-byebug at the moment.

ned-pcs avatar Jul 27 '21 15:07 ned-pcs

OK, so I made my own version of the pry command that required pry-byebug early. I still get the same :breakout_nav error upon executing a pry-byebug command, despite having start_with_pry_byebug executed.

Here's my own pry command:

#!/usr/bin/env ruby
# frozen_string_literal: true
$0 = 'pry'
require 'byebug'
require 'pry-byebug'
require 'pry'

# Process command line options and run Pry
opts = Pry::CLI.parse_options
# Pry.load_rc_files # This doesn't seem to matter
Pry::CLI.start(opts)

Here's the stack when I invoke backtrace:

[25] pry(#<MyTopLevel>):2> backtrace
UncaughtThrowError: uncaught throw :breakout_nav
from /var/lib/gems/2.7.0/gems/pry-byebug-3.9.0/lib/pry-byebug/helpers/navigation.rb:15:in `throw'
(pry) output error: #<NoMethodError: private method `eval' called for nil:NilClass>
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:454:in `select_prompt'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:95:in `read'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:68:in `block in repl'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `loop'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `repl'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `block in start'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:78:in `with_ownership'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `start'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl_file_loader.rb:30:in `interactive_mode'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl_file_loader.rb:42:in `block in non_interactive_mode'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:300:in `show_result'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:672:in `block in handle_line'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_class.rb:382:in `critical_section'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:671:in `handle_line'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:261:in `block (2 levels) in eval'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `catch'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `block in eval'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `catch'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `eval'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl_file_loader.rb:46:in `block in non_interactive_mode'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl_file_loader.rb:45:in `each'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl_file_loader.rb:45:in `non_interactive_mode'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl_file_loader.rb:69:in `block in define_additional_commands'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/block_command.rb:15:in `instance_exec'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/block_command.rb:15:in `call'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/command.rb:495:in `call_with_hooks'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/command.rb:431:in `block in call_safely'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/command.rb:439:in `use_unpatched_symbol'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/command.rb:430:in `call_safely'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/command.rb:404:in `process_line'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/command_set.rb:354:in `process_line'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:328:in `process_command'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:361:in `process_command_safely'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:610:in `handle_line'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:261:in `block (2 levels) in eval'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `catch'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `block in eval'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `catch'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `eval'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:77:in `block in repl'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `loop'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `repl'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `block in start'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:61:in `__with_ownership'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/input_lock.rb:78:in `with_ownership'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `start'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/repl.rb:15:in `start'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/pry_class.rb:191:in `start'
/var/lib/gems/2.7.0/gems/pry-byebug-3.9.0/lib/pry-byebug/pry_ext.rb:13:in `start_with_pry_byebug'
/var/lib/gems/2.7.0/gems/pry-0.13.1/lib/pry/cli.rb:119:in `start'
utilities/pry:16:in `<top (required)>'

Byebug::PryProcessor#run is nowhere on this stack.

ned-pcs avatar Jul 27 '21 17:07 ned-pcs

Any update on any chance of a pry-byebug that works with pry 0.14.0?

jrochkind avatar Jan 10 '22 17:01 jrochkind

Jonathan, not sure if this helps but you might want to switch to the new Ruby core Debug gem. You get all of Pry + Pry Byebug in a single gem now. I think the days of Pry are coming to an end.

bkuhlmann avatar Jan 10 '22 19:01 bkuhlmann

Ah, I knew the debug gem replaced byebug, but i didn't realize it ended up replacing pry too? OK, good to know, thanks @bkuhlmann

jrochkind avatar Jan 10 '22 19:01 jrochkind

you might want to switch to the new Ruby core Debug gem. You get all of Pry + Pry Byebug in a single gem now

I didn't find up command in the debug gem. Maybe there is lack of other byebug commands, not sure. Also, yes, pry is better for me than irb (colors, formatting, completion), so… it's an alternative, but not full-functional replacement.

AlexWayfer avatar Jan 11 '22 08:01 AlexWayfer

:bow: Alexander. True, it's not a full functional replacement. Fair point.

bkuhlmann avatar Jan 11 '22 13:01 bkuhlmann

#386 should fix this, can someone confirm?

deivid-rodriguez avatar Aug 15 '22 13:08 deivid-rodriguez

I've tested with pry 0.14.1 and pry-byebug 3.10.0 and had no issues.

Thanks @deivid-rodriguez !

andrehjr avatar Aug 16 '22 00:08 andrehjr

Awesome, thanks for trying it!

deivid-rodriguez avatar Aug 16 '22 04:08 deivid-rodriguez