WebFund 2015W: Assignment 8: Difference between revisions
No edit summary |
|||
(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
This assignment has 10 points. For five of the following eight error messages/conditions, please explain what small code change to [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/code/ajax-notes.zip ajax-notes] (from [[WebFund 2015W: Assignment 7|Assignment 7]]) ''or its running environment'' would produce the error (1 point) and briefly explain why this code change produces this error (1 point). You may answer one additional question for extra credit, allowing you to get a maximum score of 12 (out of 10) on this assignment. | This assignment has 10 points. For five of the following eight error messages/conditions, please explain what small code change to [http://homeostasis.scs.carleton.ca/~soma/webfund-2015w/code/ajax-notes.zip ajax-notes] (from [[WebFund 2015W: Assignment 7|Assignment 7]]) ''or its running environment'' would produce the error (1 point) and briefly explain why this code change produces this error (1 point). You may answer one additional question for extra credit, allowing you to get a maximum score of 12 (out of 10) on this assignment. | ||
Submit your answers on cuLearn in a text or PDF file by '''10 AM on Wednesday, March 25, 2015'''. No other formats will be accepted. No late assignments will be accepted! | |||
===Error 1=== | ===Error 1=== | ||
Line 49: | Line 48: | ||
The "Refresh Notes" button doesn't seem to do anything. The rest of the application seems to work fine. | The "Refresh Notes" button doesn't seem to do anything. The rest of the application seems to work fine. | ||
==Solutions== | |||
# This error happens because MongoDB is not running (e.g., it has crashed or somebody ran <tt>service mongodb stop</tt>). The application, via mc.connect(), attempts to connect to mongodb on localhost at port 27017 and gets a connection refused. This generates an error that is passed on to the anonymous callback for mc.connect(), which then calls "throw err". Because we don't have a catch statement to catch this error it causes the application to terminate with the error given above. | |||
# This error means that the handler function for / is not properly redirecting to /notes when the user is logged in. One code change that could produce this effect is the omission of the res.redirect("/notes") call in the function passed to router.get() for /. | |||
# The 500 return status code for GET /getNotes means that the handler is generating some sort of error that is being caught by the Express framework. (That is why the error is being returned to the client rather than crashing the application.) One of the simplest kinds of errors that could generate this sort of problem is an unknown identifier. For example, if "username" was instead entered as "Username" (in the if (username) test) we could get a 500 error. Or, if the declaration of username was left out at the top of the function we would get a 500 error. | |||
# The note being displayed is the one that is supposed to be sent when no user is logged in; however, the user is, indeed, logged in as evidenced by the working logout button. There is thus a logic error in the /getNotes callback. One way to generate this type of error would be to invert the if test of username (that is used to determine whether someone is logged in in the current session), e.g. by replacing "if (username)" with "if (!username)". | |||
# A new note is being added, so everything is working server side. The client (notes.js) is making the appropriate POST request because we see the note added. What we aren't seeing is the edit interface. The callback editNewNote() is responsible for initiating the call to editNote() which puts up the edit interface. Thus one way to generate the observed error would be to delete the call to editNote() in editNewNote(). | |||
# If $ is not defined, then the $() enclosing all of the code in notes.js won't be defined and so none of the code in notes.js will be run, leading to the empty interface. $ is used in our code to access jQuery, so the error means that jQuery is not being loaded properly. Thus a simple way to produce this error would be to delete the script line in layout.jade that loads jQuery. | |||
# The network view shows no GET /getNotes, which is a problem because without the data from this call there are no notes to be displayed. The first function run from notes.js is noteListing(), and one of the things it does is add a "Notes" h2 header and a "Loading Notes..." list item. Since we do not see these in implies that noteListing() is never being run. One way for this to happen would be to delete the call to noteListing() in the next to last line of notes.js. (Note that we do see a successful GET /notes.js so notes.js is being properly loaded from notes.jade.) | |||
# If the refresh notes button isn't working but otherwise the app is running properly, the problem is probably isolated to the Refresh Notes button. Its behavior is defined near the end of noteListing() in notes.js (which runs in the browser). We see the button so the append() call is working properly. The button does nothing so there is a problem with the click() handler defined for #refreshNotes. The callback getAndListNotes() is used elsewhere so it is unlikely there is a problem with it; thus the most likely problem is that the line <pre>$("#refreshNotes").click(getAndListNotes);</pre> was omitted. |
Latest revision as of 16:59, 5 April 2015
This assignment has 10 points. For five of the following eight error messages/conditions, please explain what small code change to ajax-notes (from Assignment 7) or its running environment would produce the error (1 point) and briefly explain why this code change produces this error (1 point). You may answer one additional question for extra credit, allowing you to get a maximum score of 12 (out of 10) on this assignment.
Submit your answers on cuLearn in a text or PDF file by 10 AM on Wednesday, March 25, 2015. No other formats will be accepted. No late assignments will be accepted!
Error 1
The following message was printed at the terminal prompt after running bin/www:
/home/soma/Documents/Class/WebFund/2015W/ajax-notes-broken/node_modules/mongodb/lib/mongodb/mongo_client.js:409 throw err ^ Error: failed to connect to [localhost:27017] at null.<anonymous> (/home/soma/Documents/Class/WebFund/2015W/ajax-notes-broken/node_modules/mongodb/lib/mongodb/connection/server.js:555:74) at emit (events.js:106:17) at null.<anonymous> (/home/soma/Documents/Class/WebFund/2015W/ajax-notes-broken/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:156:15) at emit (events.js:98:17) at Socket.<anonymous> (/home/soma/Documents/Class/WebFund/2015W/ajax-notes-broken/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10) at Socket.emit (events.js:95:17) at net.js:440:14 at process._tickCallback (node.js:419:13)
Error 2
You are logged in and you try to go to http://localhost:3000/ (the top-level page). Rather than redirecting to /notes the load just hangs.
Error 3
The notes listing screen only says "Loading Notes...". When you look at the network tab in the browser developer tools you notice a GET for /getNotes has returned a 500 status code.
Error 4
In the notes listing you see only one note listed with the title "Not Logged In" and contents of "Nobody seems to be logged in!". The top of the page says the current username and the logout button still works normally.
Error 5
Clicking the "New Note" button seems to do nothing. However, a POST request to /newNote has a response code of 200 and, when refreshed, there is a new, "Untitled" note added to the list.
Error 6
On the /notes page, when logged in as Alice, you only see "Alice account", "Welcome Alice", and the logout button (which works fine). In the JavaScript console in the browser you see a message "ReferenceError: $ is not defined".
Error 7
On the /notes page, when logged in as Alice, you only see "Alice account", "Welcome Alice", and the logout button (which works fine). In the JavaScript console in the browser you see no new error messages. In the network view you see four 200-code GET requests for notes, style.css, jquery-1.1.12.js and notes.js.
Error 8
The "Refresh Notes" button doesn't seem to do anything. The rest of the application seems to work fine.
Solutions
- This error happens because MongoDB is not running (e.g., it has crashed or somebody ran service mongodb stop). The application, via mc.connect(), attempts to connect to mongodb on localhost at port 27017 and gets a connection refused. This generates an error that is passed on to the anonymous callback for mc.connect(), which then calls "throw err". Because we don't have a catch statement to catch this error it causes the application to terminate with the error given above.
- This error means that the handler function for / is not properly redirecting to /notes when the user is logged in. One code change that could produce this effect is the omission of the res.redirect("/notes") call in the function passed to router.get() for /.
- The 500 return status code for GET /getNotes means that the handler is generating some sort of error that is being caught by the Express framework. (That is why the error is being returned to the client rather than crashing the application.) One of the simplest kinds of errors that could generate this sort of problem is an unknown identifier. For example, if "username" was instead entered as "Username" (in the if (username) test) we could get a 500 error. Or, if the declaration of username was left out at the top of the function we would get a 500 error.
- The note being displayed is the one that is supposed to be sent when no user is logged in; however, the user is, indeed, logged in as evidenced by the working logout button. There is thus a logic error in the /getNotes callback. One way to generate this type of error would be to invert the if test of username (that is used to determine whether someone is logged in in the current session), e.g. by replacing "if (username)" with "if (!username)".
- A new note is being added, so everything is working server side. The client (notes.js) is making the appropriate POST request because we see the note added. What we aren't seeing is the edit interface. The callback editNewNote() is responsible for initiating the call to editNote() which puts up the edit interface. Thus one way to generate the observed error would be to delete the call to editNote() in editNewNote().
- If $ is not defined, then the $() enclosing all of the code in notes.js won't be defined and so none of the code in notes.js will be run, leading to the empty interface. $ is used in our code to access jQuery, so the error means that jQuery is not being loaded properly. Thus a simple way to produce this error would be to delete the script line in layout.jade that loads jQuery.
- The network view shows no GET /getNotes, which is a problem because without the data from this call there are no notes to be displayed. The first function run from notes.js is noteListing(), and one of the things it does is add a "Notes" h2 header and a "Loading Notes..." list item. Since we do not see these in implies that noteListing() is never being run. One way for this to happen would be to delete the call to noteListing() in the next to last line of notes.js. (Note that we do see a successful GET /notes.js so notes.js is being properly loaded from notes.jade.)
- If the refresh notes button isn't working but otherwise the app is running properly, the problem is probably isolated to the Refresh Notes button. Its behavior is defined near the end of noteListing() in notes.js (which runs in the browser). We see the button so the append() call is working properly. The button does nothing so there is a problem with the click() handler defined for #refreshNotes. The callback getAndListNotes() is used elsewhere so it is unlikely there is a problem with it; thus the most likely problem is that the line
$("#refreshNotes").click(getAndListNotes);
was omitted.