Debugging Ruby with Byebug

A guide on Byebug exists here

Couple of useful links:

https://fleeblewidget.co.uk/2014/05/byebug-cheatsheet/

Tips:

Disappearing type!

At the moment it seems like the bash terminal can stop echoing your typing mid debug session. A simple workaround is to paste and enter this string, and the echoing will return:

`stty sane`

This is a known issue

You can make this even easier by binding this to a key combo, e.g. here in VS Code:

image

[{"key": "ctrl+u",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "`stty sane`" }}]

(NB I don’t think this is yet possible in the new Windows Terminal app, though, but feel free to amend this statement!)

Reduce the splurge to terminal

Consider getting rid of the SQL logging using this addition to /config/environments/development.rb

config.active_record.logger = nil

Reduce the number of unicorns in unicorn.conf.rb:

worker_processes (ENV["UNICORN_WORKERS"] || 1).to_i (from usually 3 to 1)

Finally, stop the system repeatedly failing to send mail:

mailcatcher --http-ip 0.0.0.0

3 Likes

I’ve added a couple more tips in ‘reduce splurge’ section:

I see why you reduced the workers. Trying out byebug

1 Like

Another thing to consider:

  • offload functionality from the Controller into library methods so you can test it in quiet isolation. The loss of visible text becomes really annoying with byebug, so for this reason alone it’s worthwhile.
1 Like

Another thing I’m going to try is stop other threads whilst in a Controller, so see if that helps:

1 Like

Something similar but needs no code tweaking

ENV['DISCOURSE_DEV_LOG_LEVEL']

You set this variable to change the rails log level while starting the server.

1 Like

Setting DISCOURSE_DEV_LOG_LEVEL=info gets rid of sql logging.

1 Like