May Your Errors Light the Way


This post was written by Justin Herrick, Austin’s Ruby on Rails Instructor. View his profile on The Iron Yard’s website and follow him on Twitter!

It’s human nature to want to avoid mistakes. We want to make progress and mistakes seem like the antithesis to progress. However, sometimes we can learn more from a mistake than we would from smoothly sailing forward. I think this is demonstrated exceedingly well when programming.

A mistake in your code could reveal more about the nature of your code and the libraries it is using. Take for example this common situation in Rails.

class GameController < ApplicationController
  def about_game
Rails.application.routes.draw do
  get ‘about_game’ => ‘game#about_game’

I create a new action in my controller and I also create a route pointing to my action, but when I navigate to that route I get an error. Specifically, I get this error.

Missing template game/about_game, application/about_game with
{:locale=>[:en], :formats=>[:html], :variants=>[], 
 :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. 
 Searched in: * "/Users/Justin/theironyard/week_2/thursday/hello_web/app/views"

Great. I messed up. Now I gotta figure out why my code doesn’t work. Rails is saying my template forgame/about_game is missing. It also says that it tried looking in app/views. With a little bit of context, we can see that this error is actually telling us what we need to do, not just what the mistake was. Rails says it cannot find the template for our new route and that we should create it inside ofapp/views. Not only that, but that it should be inside of game/ and named about_game. Well, that wasn’t too hard to fix. I also learned a little about Rails in the process. Rails looks for templates inside of the view/ directory and then looks for a directory that matches the name of the controller and a file that matches the name of the action.

Mistakes happen, errors occur. When developing software, they are more than a daily occurrence, they are an hourly or minute to minute occurrence. The key is to realize that errors are good, they are here to help you. They are giving you feedback about the state of what you are building. They are just one more step in growing as a developer, and as you grow, you will make less errors and build your own system for handling those errors. My steps for when I run into an error normally go something like this:

  1. Stop and take the time to understand what the error is telling me.
  2. Discover where the error is coming from.
  3. Look for typos.
  4. Make sure my files are saved.
  5. Walk through the logic of my code right up until the error occurs. Normally this is done out loud and with someone listening.
  6. Try it again.
  7. If the the piece of code and the error are modular enough, I will try to replicate the code in a REPL and see if the error exists there as well.
  8. If the error is hard to pin down, I will start to remove sections of code systematically to find the problem area. Allowing me to focus my search
  9. Consult peers who may have run into the same issue.
  10. Search the internet for others who have may have found this issue and also found the solution.

I rarely find an error that cannot be solved by making it through this list and even rarer yet is the error where there is no learning to be found.

Many times when I talk to a student who is stuck, I find myself telling them that it is time to put on our detective caps. Feeling helpless or frustrated where an error occurs is normal, but its not very productive. By taking the time to re-approach the error as a clue of where to go next, instead of a stop sign, I have turned a potential setback into a positive.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About theironyard

The Iron Yard exists to create exceptional growth and mentorship for people, their companies and their ideas through code education and startup accelerators.