ProdoElmit
ProdoElmit

Reputation: 1067

Set a breakpoint in lib/ directory of rails

I've put the code which processes document generation to lib/parser folder in my Rails application. But now I can't debug that code: neither binding.pry nor byebug have an effect. Raising exceptions also doesn't show up neither in logs nor in rails server's stdout channel. Is there any way to fine-tune it, or to debug it I have to put it somewhere else?

The module itself is included in controller with

require Rails.root.join("lib/parser/parser.rb")

Upvotes: 1

Views: 756

Answers (2)

ProdoElmit
ProdoElmit

Reputation: 1067

Thanks to @Naremy, I've found my mistake. The problem was following: I've had begin...rescue block which was catching errors stopping them from floating up to output of rails server. And as the error was the same as in the other chunk of code (where I was trying to set breakpoint), I couldn't find it. So removing rescue made a move, and now everything works as expected.

So the overall fact is: if you catch a error, neither rails server output nor better_errors gem will show you anything.

Upvotes: 1

Naremy
Naremy

Reputation: 611

You can relaunch your server after each change and it will work but if you have a lot of code it can be long.

You can also add your code in the autoload_paths (into application.rb) :

config.autoload_paths += Dir[Rails.root.join('lib', '**/')]

See also Auto-loading lib files in Rails 4

Upvotes: 1

Related Questions