Matt
Matt

Reputation: 1969

Debugging Backbone.js

I'm looking for some guidance in debugging backbone.js. I'm following the Daily.js backbone tutorials and have run into a bug after week 9 (http://dailyjs.com/2013/01/24/backbone-tutorial-9/).

This is the error I have

[22:47:29.339] "calling request execute"
[22:47:29.423] GET http://localhost:8080/img/glyphicons-halflings.png [HTTP/1.1 304 Not Modified 1ms]
[22:47:29.424] POST https://content.googleapis.com/rpc?key=xxxxxxx [HTTP/1.1 200 OK 168ms]
[22:47:29.546] ReferenceError: id is not defined @ http://localhost:8080/js/lib/underscore.js:1209
[22:47:29.543] "calling options success"

Here's the code with corresponding console logging calls:

  Backbone.gapiRequest = function(request, method, model, options) {
    var result;
    console.log("calling request execute")
    request.execute(function(res) {
      if (res.error) {
        if (options.error) options.error(res);
      } else if (options.success) {
        if (res.items) {
          result = res.items;
        } else {
          result = res;
        }
        console.log("calling options success");
        options.success(model, result, request);
      }
      console.log("gapiRequest")
    });
  };

To things are throwing me presently:

  1. why the last log (of gapiRequest) isn't being displayed.
  2. why the error occurs between the two console logs, even though nothing in the code refers to id or, as far as i can see, any external libs.

If anyone is aware of what may be happening that would be great, any info on how to debug this would be very good as well. Can stack traces be produced in current web browsers?

TIA, Matt

Upvotes: 0

Views: 524

Answers (1)

Akos K
Akos K

Reputation: 7133

  1. your script is crashed, if you look at the timestamps:

    [22:47:29.546] ReferenceError: id is not defined @ http://localhost:8080/js/lib/underscore.js:1209
    [22:47:29.543] "calling options success"
    

    you will see that "calling options success" happened before the ReferenceError. Meaning that your client received the result but your script is crashed while rendering the template (I guess), probably because:

  2. judging by the library where the exception happened (underscore.js) you probably reference id somewhere in your underscore template. Look for something like <%= id%> or <% id%> in your template file.

Upvotes: 2

Related Questions