0

I am new to ruby, we have a ROR microservice(rails version 6.1) , recently i updated the ruby version on the service from 2.7 to 3.0 , after this since there were failures and i wanted to debug it, so i added binding.pry , when the binding.pry is encountered the flow stops but its doesnt show the exact line where the binding.pry has stopped in the console and no matter what command i give it conitnues the flow .

screenshot of console when binding.pry is encountered in code

Below are the relevant gems versions from gemfile


  ruby '>=3.0'
  gem 'rails', '~> 6.1'
  gem 'pry', '~> 0.10.3'
  gem 'pry-byebug', '~> 3.4'
  gem 'pry-rails', '~> 0.3'
  gem 'rdoc', '>= 6.3.1'
gem 'webrick', '~> 1.8'

I want to get the binding.pry to work properly, how it used to with older ruby 2.7 version, so that i could debug the actual issues that the service is facing after 3.0 upgrade Please suggest me guys.

EDIT 1: I want the output on the console once the binding.pry is encountered to be something like this:

    2: def example()
    3:   str="this is an example string"
    4:   arr= ["abc", "xyz" , "geh"]
 => 5:   binding.pry
    6:   arr[0]
    7:
    8: end
  • Hi, welcome to Stack Overflow, did you check the already answered questions for a similar issue? There are plenty of other questions with a similar issue and with multiple solutions already provided. If you've already tried those, can you please mention what solutions you've already tried so that we can narrow down the root cause? – KunalK Feb 17 '23 at 13:00
  • @KunalK I tried finding to search for similar problem but i couldn't find anything similar online, The issue I'm facing is that when binding.pry is encountered , i can see the console waiting for my input but it doesn't highlight the line that is currently being pointed. @ – Caterpillar Feb 19 '23 at 17:10
  • @anothermh gem 'webrick', '~> 1.8', steps I'm following: adding binding.pry to controller file or any file, hitting the endpoint in postman which would in turn execute the code where binding.pry is added, flow will stop and wait on the terminal but doesnt show which line the executed has stopped at. – Caterpillar Feb 19 '23 at 17:11
  • @anothermh there's nothing on the output screen that's why I didnt add anything , the queries get executed and when the binding.pry is encountered (which I've added in controller file) the console just waits . I've added screenshot for your reference. – Caterpillar Feb 20 '23 at 09:48
  • As someone that tries to answer questions frequently here, it is very frustrating to me when I ask multiple times that you please copy and paste plaintext into your post demonstrating the issue and you refuse every time, even though you clearly have access to the plaintext and can demonstrate it by copying and pasting it into your post. – anothermh Feb 20 '23 at 22:27

2 Answers2

0

I've often run into the issue where, if I put a binding.pry to test an endpoint (whether using Postman or localhost), and the request is either sent multiple times due to redirects or the entity sending the request sends it multiple times, the console won't respond. It'll stop at the break point but I can't type anything.

My fix

What I usually do to fix this is send one request then quickly stop the request (canceling the Postman request). Then I'll go into the console and try to type something, if I can't, I'll type exit, try to type something again, type exit etc. until I can type in the console. The idea is I'm trying to get to the last request that was sent.

  • I am able to type whatever I want in cosole once the cursor stops at the breakpoint where i've added bnding.pry, but the issue is that i cant see the source code where the pointer is at in my console like how I've edited my original question – Caterpillar Feb 22 '23 at 17:22
  • @Caterpillar using `binding.pry` won't show you the source code. Your original question involves the problem of the flow continuing no matter what you put in the terminal. My answer addresses that. As for seeing the source code, pry won't show you the code as it is in the terminal. – Travis McKinstry Jun 01 '23 at 00:05
0

Pry does not support Ruby 3 until version 0.14.0, so you need to update pry to >= 0.14

Ezra-Shimon
  • 35
  • 2
  • 7