Better_Errors: A Lifesaver!

Dwayne McFarlane
Nov 4 · 3 min read

As developers, we rely on error messages to help guide us as to what aspects of our applications need more attention when things don’t go as expected. Ruby, more than many other programming languages, provides users with detailed error messages that attempt to pinpoint the actual source driving the error. However, there are times when even Ruby’s native error message system can be a bit misleading. As our applications become larger and more complex, a simple misleading application error message can easily lead to hours of wasted time searching for and changing the wrong lines of code. Intro “Better_Errors.”

Better Errors is a Rails gem that the Railsgem repository describes as a gem that “ …replaces the standard Rails error page with a much better and more useful error page….” In practice, I found this gem extremely helpful. For example, I intentionally left off an ‘end’ tag in a blog application that I was building in rails and this was the error message that the native Rails gem threw me:

Original Error Message
Original Error Message
Native Rails Error Message

Obviously, since I made the coding error on purpose, I knew that this error message was not what was actually causing the issue. This is where the beauty of the Better_Errors come into play. Once activated, I then refreshed the application and this was the error message that I received:

Better Errors Error Message
Better Errors Error Message
Errors with better errors

Talk about spot on! Not only did the Better Errors gem tell me exactly what was wrong, but it also let me know exactly what file the error could be found in. AMAZING.

Amazed

Installation

So now that we know we want Better Errors, the next step is to get it installed. Luckily , that’s super simple as well. Simply visit the RubyGems repository and type in “Better_Errors”. Click on the link with the most downloads(Currently about 22mm) and then just copy and paste the code into your gem file and then bundle install. Be sure to place the code in the development section of your gemfile, or it may not work. It’s as simple as that and then you too will have Better Errors.

Better Errors Installation
Better Errors Installation
How to install Better Errors

Enjoy!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade