TUTORIAL: Debugging Blanket Errors

Note: this post is an extension on my earlier debugging guide: JavaScript Debug Chart, the second in a series about debugging.

Sometimes, your browser will give you an error so unspecific, you’ll want to throw tomatoes at it. For example: “TypeError: Undefined is not a function”.  This happened to me the other day while working on an exercism.

No matter what I did, it seemed like the error stayed the same and my frustration level grew. And tools like repl.it and JS Hint weren’t helpful; they just gave me the same error as the console with no explanation.

A few days later, I’ve now fixed my code and wanted to post some lessons learned for those in a similar situation, because If you’ve already ruled out everything you know, blanket errors like this one may need their own debugging process.  Here are a few steps to get you started:

1. What did you last work on?

If your code was working 5 minutes ago, you are the culprit.  Try undoing or going back to an earlier git version.

2. De-nest.

You’re going to have to pull your code down to the smallest building blocks so that you can examine each piece and see where the code is going wrong.  You can test smaller code chunks individually in repl.it, using repl’s console to plug in variables.

3. Re-organize.

If you’re working with a number of interdependent functions, it’s likely that one of your functions or variables is simply defined too far down in your code, causing the browser to throw an “undefined” error.  Look through and make sure each variable, function, script is defined before it is called.


Surviving Bootcamp

I’m now coding 8-9 hours a day at FullStack and at home.  That’s on top of 2 hours of commuting (when I’m also reading coding blogs…). This can be mentally and physically exhausting, but after six weeks, I’ve learned some tricks to keep me going. 


1. Plan Ahead

I don’t have time to rush around the house looking for my shoes, or to run out to the grocery store at the last minute if I forgot something.  I plan the week’s meals — lunch and dinner — on the weekends, and prepare anything I’ll need.  I tend to cook in bulk and eat a lot of leftovers. Likewise, each night I pack my bag for the next day, including laying out my clothes on a chair.  

2. Healthy Snacks

I keep healthy snacks around at all times to keep me energized.  There’s nothing more awful than the feeling I get after eating a bunch of junk food.  When I’m tempted to eat a big bowl of ice cream, I head for the orange juice pops in my freezer.  I keep almonds in my bag, for the days when I’m on the go and need some sustenance.  When I’m coding and I get the munchies, I turn to fresh veggies like celery and carrots, or to those thick pretzels that have satisfying crunch with very few calories.  I always eat a lot of protein for lunch, and that combined with healthy snacks sustains me through the day.

3. Flow

Each day, I try to do one activity that completely takes my mind off of coding, something I really enjoy.  The ones that work best are right-brained activities where you can get totally absorbed.  I like playing the piano, working on an art project or a puzzle, or tackling an organization project around the house.  I finish these activities feeling refreshed, almost as if some kind of reset button has been triggered in my mind.

**CAUTION: Approaching Max Frustration**

My day coding today was terrible. Think Alexander and the Terrible, Horrible, No-good, Very Bad Day, but substitute a recurring ‘CANNOT PERFORM FUNCTION ON UNDEFINED’ for the lima beans.

We’ve been working on mongo.db (databases built through objects instead of columns) and using it to build our own wikis. In the course of the day today, I broke everything I worked on: the database, the wiki, another page I worked on.  My breaking streak spanned the entire day, includiError Messagesng sharing an idea during the lecture that ‘broke’ the document we were learning from, hence lecture = over.

And that, my friends, is the coding profession in a nutshell.  The goal is to get a program to work once, then to not ever have to touch it again, because in editing it you will invariably break it AND the 100 other scripts attached to it.  And, as in life, it is important to be able to accept a failure, walk away, and come back with new ideas.  Again.  And again.  And again.  And a-… Can someone throw me a loop function?