Tips & tricks
How to debug?
Is it really a bug?
Can I find an error message?
Yes! Does it ring a bell, or does it give some clues about the place in the code where the bug happens? There is often a line number, but you might need to scroll down/up to find it.
No. That's probably not the case, did you look at the right place? If the error happened in the front-end, you need to check the Chrome console. If it happened in the back-end, you need to check your server logs (and/or your sidekiq logs if it's running, the error might come from there too!)
No, I swear! Ok, then you need to isolate the issue at maximum. This becomes a game of finding some clue, so put your hat on and stop at every line of code of your flow if you need to.
After you located the error, you need to understand how it happened, under what conditions it can occur and how you should fix it. Beware that your fix does not break something else, by making sure you truly understand what is happening. No rush here, this is the more important step. Go down that rabbit hole 🐰
If you're lost, it's ok and it happens, no worries. You best friend for that is Stackoverflow, remember that thousands of people have probably been where you are now, so look for their solutions.
NB: sometimes, you'll get some error in the back-end while everything looks fine. Maybe the error spawns in the back-end because the front-end sends the wrong data? Go back on the flow, and make sure the front-end does its job correctly.
Common bugs
Address already in use
You try to run your server with foreman and boom, you get an "address already in use" kind of error. This probably means that some processes were not closed properly (e.g. your computer shutted down), and you'll need to manually kill them.
Basically, it means that you try to start a new server at a specific port and it tells you that this port is already used (while you know that your server ain't running).
To kill it manually, you'll first need to find the process ID (PID):
Run
lsof -i :8080to find existing processes for the 8080 portWhen you have the right PID, kill it by running
kill -9 <PID>
The -9 is just there to force your computer to shut it, just replace <PID> with the one you found and it should be good!
DATABASE_URL
This env variable, if set, takes over the database.yml file. This file tells Rails which DB to use with which environment. For example, for the test environment (when you run Rspec), you expect Rails to run it with the test DB.
However, if the DATABASE_URL is set in your .env file, Rails won't look at the database.yml file but will use the value you referred in your .env.
With this variable set, Rails will use your dev DB even for the test environment. Your tests will fail by dozens and you'll be very confused!
The question now is: why would you ever want to have that variable in your local environment?
Short answer is: you need it for Forest Admin.
Basically, if you need to run Forest Admin locally, you'll need that variable. When you're done, don't forget to comment it (this way it stays in your file, but won't have any effect).
Process is not defined
You're missing an .env variable. Good thing is that you know how to debug, so you'll look the Chrome console and see the error, which will show you the exact line that failed ;)
See the above video for example: by inspecting we can quickly land on the right line, and we see that I currently miss the LANDING_BOT_CANDIDATE_EN key.
After adding the missing key, don't forget to restart your environments (server, rails console, Sidekiq) to make it available!
Cannot connect on localhost
Can be many things, but often linked to your Postgres:
Try reinstalling it with the right version
Run « createdb » in a bash terminal (this should create a DB named after you on your machine)
If this command was not known, it means that Postgres installation failed
Run rails db:reset
Look on stack overflow, it may need some try & repeat
Searchkick Import - TOO MANY REQUESTS
This error occurs when your local server for Elasticsearch is full. To flush it, simply run this in a bash terminal:
This is a simple DELETE request to your local Elasticsearch server, which is hosted in the 9200 port.
Missing libraries
Don’t forget to run yarn & bundle to make sure you’re up to date.
Last updated