Debugging Part 1

One of the first and most natural types of debugging is just looking through our code for typos, misused variables, or errors given to us by our text editor. In the screenshot below we will see some examples of errors given by our text editor.

Screen-Shot-2018-10-09-at-3.14.10-PM

Take a minute to look at the code above and compare the working examples to their broken counterparts. Familiarizing yourself with these helpful hints will greatly assist you in resolving bugs within your code.

Another useful tool are the errors given to you by Node.js in your Terminal. Below are some examples taken from the Daily Planet Editor.

Screen-Shot-2018-10-09-at-2.47.39-PM

At first glance this error can seem quite overwhelming, but let's take a closer look.

  1. If you look at the second line and go to the very end of the line you will see paper.js:14
    • This is indicating to you the location of the error. paper.js is the file the error is found in and :14 is the line within that file that the error is found on.
  2. The line directly below that shows that line with the error and points at the breaking point.
    • It is important to note that where it is pointing is not always the exact location of the error but rather where the code is breaking due to the error.
    • The error in this example is that the word function is missing the letter c.
  3. The last piece to pay attention to is the line that reads SyntaxError: Unexpected identifier.
    • If you cannot figure out what the error is, this is a good line to copy and paste into a google search.
    • There are lots of lines below this line but you will rarely if ever use these lines to help you identify bugs in your code.

Debugging with Google

Screen-Shot-2018-10-10-at-10.52.11-AM

You will notice above that we have googled the same error from our above example, but we added in the word node. When googling errors or anything code related, it is always a good idea to tag on at the end the language you are using. If I were using vanillaJS you would write js at the end instead of node, if you were using React you would write react, if you were using python you would write python etc...

Stack Overflow

You will often be lead to a stack overflow link when searching errors or specific bugs.

Use the video below as a guide for where to look on these pages

stack-overflow-2

  • Look to see if your answer might be in the description on the link.
  • Once on the page, scroll down to the answers section, the best answer is usually first and indicated with a green checkmark
  • This is a good place to read to find the solution to your problem.
  • If your problem is not found there just repeat this process until you find your solution.

Other Google resources

With regards to the Daily Planet Editor, run the code in Node.js. This will show you an error similar to the one shown at the beginning of this write-up. Follow the processes explained, then run the code again and see if you get the same error or a different one. Repeat this until you no longer get any errors and the code seems to be running as expected.