Pry: Silencing command output confuses pry

Created on 15 Mar 2012  路  6Comments  路  Source: pry/pry

Here's a short pry session demonstrating the error message I'm seeing.

$ pry
[1] pry(main)> s = File.read("data.json");
Error: Cannot find local context. Did you use `binding.pry`?

Most helpful comment

Another solution might be to use double letters for navigation. (Here's an example from my ~/.pryrc, so there's obviously a little more you'd have to do if you're using pry-nav.)

if defined?(PryDebugger) or defined?(PryByebug)
  Pry.commands.alias_command 'cc', 'continue'
  Pry.commands.alias_command 'ss', 'step'
  Pry.commands.alias_command 'nn', 'next'
  Pry.commands.alias_command 'ff', 'finish'
end

Then you only have to think about it when you're using the navigation commands, and you don't have worry about a name collision when you do something like

c = Conversation.new

at the Rails console.

All 6 comments

A better reproduction might be needed:

macbookair% pry
[1] pry(main)> "Hello";
[2] pry(main)> 

Super large strings do not make a difference:

[3] pry(main)> "h"*5_000_000;
[4] pry(main)> 

Pry version is 0.9.8.4.

@duncanbeevers this is caused by a feature/bug in pry-nav which creates commands called s and c and n. See: https://github.com/nixme/pry-nav/issues/3

This is luckily really easy to work around, just put

Pry::Commands.delete 'c'
Pry::Commands.delete 'n'
Pry::Commands.delete 's'

into your ~/.pryrc

Beauty. I actually use the c, n, and s commands a lot, so I guess I just need to be mindful of what locals I'm creating.

Hmm, we do have an experimental feature that gives a better error message in this case. I'll see how much more work it needs to be enabled by default. Thanks for the feedback.

@ConradIrwin how did it go with better error messages?

I don't have pry-nav installed:

$ gem list | grep pry
pry (0.9.12.4, 0.9.12.3, 0.9.12.2)
pry-byebug (1.2.0)
pry-doc (0.4.6)

And trying the work around I get:

$ cat ~/.pryrc
Pry::Commands.delete 'c'
Pry::Commands.delete 'n'
Pry::Commands.delete 's'
$ pry
Error loading ./.pryrc: Cannot find a command: 'c'!
/Users/dentarg/.gem/ruby/2.0.0/gems/pry-0.9.12.4/lib/pry/command_set.rb:201:in `find_command_by_match_or_listing'
[1] pry(main)>
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin12.5.0]

Another solution might be to use double letters for navigation. (Here's an example from my ~/.pryrc, so there's obviously a little more you'd have to do if you're using pry-nav.)

if defined?(PryDebugger) or defined?(PryByebug)
  Pry.commands.alias_command 'cc', 'continue'
  Pry.commands.alias_command 'ss', 'step'
  Pry.commands.alias_command 'nn', 'next'
  Pry.commands.alias_command 'ff', 'finish'
end

Then you only have to think about it when you're using the navigation commands, and you don't have worry about a name collision when you do something like

c = Conversation.new

at the Rails console.

Was this page helpful?
0 / 5 - 0 ratings