3

I'm following along with a tutorial book, and in order to step through my code I've required pry and added a binding.pry reference in a method which gets executed:

require 'pry'

module Rulers
  module Model
    class FileModel
      def initialize(filename)
        @filename = filename
        binding.pry
        basename = File.split(filename)[-1]
...

When I load the code which executes this constructor method, I successfully hit my binding.pry debugger point as expected. However, when I start typing commands at the prompt, the characters I enter are printed out in the same prompt:

[7] pry(#<Rulers::Model::FileModel>)> .whic.whichh

In the above example, I typed .which. I had gotten all the way to .whic when the REPL added the characters I had typed thus far (i.e. it added .whic to .whic, resulting in .whic.whic). The last character I typed was h, which registers after .whic.whic. Finally, the last h I typed was also appended to the chars on the prompt.

Interestingly, the duplicated chars do not appear to affect the REPL's ability to understand the commands I type in. For example, the following:

[8] pry(#<Rulers::Model::FileModel>)> .which .which vim
[8] pry(#<Rulers::Model::FileModel>)> .which vim
/usr/bin/vim

In the above example, I was successful in typing .which quickly enough to not result in a muddled version of the which command, and I also pressed Enter before vim could be duplicated erroneously. If the redundant 2nd .which command were to affect my ability to return the expected output, I would expect to see an error returned. Instead, I see /usr/bin/vim as I would expect when typing which vim in my regular, non-pry command line prompt.

I have no theories on where to begin debugging this. Any ideas?

5
  • 2
    I have seen this before. Is this breakpoint happening during a request, by chance? I think it might have to do with the web server being multithreaded but not 100% sure. You can also try byebug debugger and see if it has the same issue. Commented Apr 4, 2021 at 22:42
  • What environment is this run in? What exactly is the tutorial? Max is on the right track here I think. This can happen if another thread or process is reading the tty you are working on at the same time. It can also happen with Rails if Spring is used to speed up reloading, as Spring does some funky stuff with the tty. In that case remove Spring from your Gemfile and try again. Commented Apr 5, 2021 at 17:55
  • @Casper this is run on my local machine, in the :development environment, using the "Rebuilding Rails" tutorial. The app runs a simple WEBrick server, executed using bundle exec rerun -- rackup -p 3001. Commented Apr 5, 2021 at 19:43
  • And you do not have Spring in your Gemfile? To reduce moving parts I would also run it without rerun, just to make sure you can eliminate as many parts as possible which could be causing the issue. Commented Apr 5, 2021 at 22:20
  • 1
    No Spring in the Gemfile. Funnily enough, your suggestion to remove the rerun reference seems to have done the trick! I removed it and restarted the server with a simple bundle exec rackup -p 3001 and things seemed to work fine even over a significant length of time. Then I killed the server and restarted it with rerun prepended again, and the problem re-appeared. Commented Apr 6, 2021 at 2:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.