How to remote debug a rails 3.0.2 - ruby-on-rails

I have a bug in my application which is only happening on 'stage' but not locally. I would like to use a debugger and set a breakpoint so I can debug the application on stage.
Locally I use pry and even got the pry-remote to work locally but couldn't get it to work on the server.
I don't mind using the regular debugger or pry for the debugging.
The problem I am usually hit with:
ArgumentError (non-absolute home)
Thanks.

If you're definitely not putting this out into a production environment while you're testing it, I would recommend the better_errors Gem. It's definitely not for a production site though as it would expose some serious security issues
If you include it in the :development group it will give you a console in the webpage whenever an error is occurring.
If it's not raising a fatal error, then you can throw the raise method anywhere you want to act like a breakpoint, you won't be able to continue on, but it's useful to help do pry like stuff in the webpage.
There's a good guide by Ryan Bates
http://railscasts.com/episodes/402-better-errors-railspanel

One solution to reproduce the error locally is to start your server in the same environment that is failing.
$ RAILS_ENV=staging script/server

Related

Rails returns HTTP 500 for every page with no error log after bundle install

Today I tried to install a gem using bundler. It complained about super-user privileges so I ran it to install to vendor/bundle, and then all of a sudden every page in my app returns HTTP 500 for seemingly no reason. I re-ran bundler to install globally, and that didn't solve the problem.
In typical rails fashion, it just exits with the 500 error page without printing anything to the logs. Routing is functioning normally, the console says it renders the appropriate view, and active record seems to be working as normal, but after all of that it just shows an error page. No errors on the console or in logs/.
I'm not sure why bundler would cause this issue but I'm completely out of ideas. I've done a good bit of googling but all of the other similar situations I've found were because of a misconfigured model or database, which I know with certainty isn't the case. If anyone more familiar with Rails than me could give me a place to start I'd be very grateful.
Update: Running bundler doctor fails b/c the directory /opt/rubies/ruby-2.6.5/lib/ruby/gems/2.6.0/bundler doesn't exist - looking for issues related to this.
Solved; ultimately this was because I forgot to delete an old requirement in application.js. It still seems absolutely ludicrous to me that rails would exit 500 without an error message with no way to access more verbose debug logs

Debugging rails on passenger

I am running a Rails 5 API on passenger locally.
I start the server with passenger start command.
I installed both byebug and pry-rails but none of them are working for me.
I put a debug point, either with byebug or binding.pry, and when the code hits that point it does print the debug point in the server logs, with the code that it is executing but it doesn't actually stop, and I can type but I don't see the results of what I type.
I am starting to believe, based on posts like this one:
https://coderwall.com/p/rtskuw/create-break-points-in-rails-with-passenger-phusion-pry-pry-remote
that I can't actually debug like I debugged on rails s with passenger, but I don't actually want to believe that. There must be an easy way for me to debug the rails code on my passenger terminal without having to open a different terminal to act as a remote client or something like that.
Thank you very much

Rails not logging requests

I'm utterly stumped as to why I'm not able to see the Rails controller outputs in my development log. I've spent days beating my head against a wall trying to figure this out and I'm not sure what else to try.
Setup: Rails 5.2.3 app running ruby 2.6.3 via docker-compose.
It started with me not being able to see my app logs when running docker logs <container-name>. However, I soon realized that I was able to see the output from puma starting and a shell script that ran rake tasks that the issue might be with rails.
To help assist with finding the issue:
Tore down and rebuilt the docker environment, several times
Stopped writing via STDOUT in favor of logs/development.log
Disabled lograge and elastic-apm, just in case
Reverted my development.rb config back to what's generated with a rails new
Followed the suggestions here
However, when running the rails console via docker exec -it <container-name>:
Running Rails.logger.level returns 2 which is warn, despite the default logging level being dev
I'm able to see log output when running Rails.logger.warn 'foo'
After setting Rails.logger.level = 0 I'm able to see output when running Rails.logger.debug 'foo'
I tried setting the value explicitly as config.log_level = :debug in development.rb yet it still set itself to the warn level.
However, I'm still not able to see any logs when navigating the application. Any thoughts?
Ugh. I feel like the biggest schmuck but I've figured out the issue.
I went back though source-control to see what has changed recently. In addition to the elastic-apm gem, I also added the Unleash gem.
I went to check out it's configuration and it looks like following their recommenced configuration causes logging to break. The line that was specifically causing offense was in the unleash initializer setting config.logger = Rails.logger

How to properly diagnose a 500 error (Rails, Passenger, Nginx, Postgres)

I'm having a real tough time diagnosing a 500 error from my application running in production. I've had it working before, but after re-deploying via Capastrano I am unable to get it going.
Here are the facts:
The server is setup with nginx + passenger, and I'm using
PostgreSQL.
Static assets are working properly, as in I'm able to access them just fine in a browser.
I can access the rails console via RAILS_ENV=production bundle exec rails console and perform Active Record actions (like
retrieving data from the db).
Within console, I can run app.get("/"), which returns a 500 error as well (after first showing the query that was run to load
the model).
The production.log file is never written to. I've set permissions 777 on it just for the hell of it. I've also set the log level to
:debug with nothing to show for it.
The nginx log (which passenger also uses) shows no indication of errors, it just notifies about cache misses.
Because nothing of use is being logged, I have no idea what to do here. I've tried setting full permission on the entire app directory with no help. Restarted the server multiple times, nothing. The database is there and rails can clearly communicate with it. I'm not sure what I did to get it to run the first time around. I just don't know why rails isn't outputting anything to the log.
Okay, I figured this out. The app ran fine in development mode, so I knew something production-specific was screwing it up. I went into config/environments/production.rb and changes these settings:
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false # changed from true
config.action_controller.perform_caching = true # changed from false
And then after restarting passenger, rails showed me the error w/ stacktrace. Turns out I was forgetting to precompile the asset pipeline!
Things to check
1) Are you sure you are running in production environment?
Check to see if any entries are in the development.log file
2) Set up your app to email you when a 500 error occurs with a full stack trace. I use the Exception Notifier gem but there are plenty of other solutions for this.
3) When checking your app in the console are you sure you are starting the console in production mode? It is possible that the app is not starting up at all and you just forgot to set the production param thereby thinking that the app runs fine when it doesn't.
4) Are you getting an nginx 500 error or the Rails 500 error? If nginx then it is likely that your app is not starting at all and highly unlikely that you will get any rails error in your log file. The assets are static files and navigating to them proves nothing other than that they exist.
5) Are you sure you are checking the right folder on the server? Sounds really stupid but capistrano could be deploying the app to a folder that is different to the folder that nginx is looking for for your app so double check both the folder capistrano is deploying to and the folder that nginx is looking for are the same.
Just a suggestion, I would use puma rather than passenger. It's awesome with nginx.
My problem is passenger's log file (error.log) has nothing. Then it's a rotation log issue. Run
passenger-config reopen-logs
solved my problem. More.
Have you tried running in development mode to see if the error reports itself?

No log messages in production.log

I wrote a demo HelloWorld Rails app and tested it with WEBrick (it doesn't even use a DB, it's just a controller which prints "hello world"). Then I tried to deploy it to a local Apache powered with Passenger. In fact this test is just to get Passenger working (it's my first deploy on Apache). Now I'm not even sure that Passenger works, but I don't get any error on the Apache side.
When I fire http://rails.test/ the browser shows the Rails 500 error page - so I assume that Passenger works. I want to investigate the logs, but it happens that production.log is empty! I don't think it's a permission problem, because if I delete the file, it is recreated when I reload the page. I tried to change the log level in conf/environments/production.rb, tried to manually write to log file with Rails console production and
Rails.logger.error('asdf')
it returns true but nothing gets written to production.log. The path (obtained per Rails.logger.inspect) is correct, and I remark that the file is recreated if I manually remove it. How can I know what's going on?
(I already checked the Apache logs, plus I set the highest debug level for Passenger but it seems a Rails problem, so is not logged by the server)
Assuming you're running Rails 3.2.1, this is a bug. It was patched in 3.2.2.
If you can't upgrade to 3.2.2 for any reason, this comment on GitHub has a workaround:
# config/initializers/patch_rails_production_logging.rb
Rails.logger.instance_variable_get(:#logger).instance_variable_get(:#log_dest).sync = true if Rails.logger
Setting this works on Rails 3.2.11:
Rails.logger = ActiveSupport::BufferedLogger.new(Rails.root.join("log","production.log"))

Resources