framework
framework copied to clipboard
Invalid Javascript is sometimes not reported on console
From this thread
Nope, this is actually a much more pernicious problem that I've seen many times. It is indeed a bit of a pain, but it's also a bit hard to solve. When the JS hits the client, jQuery attempts to eval it as JavaScript. But, when it goes to do that, the JavaScript fails to parse, so nothing gets to run! This means that the JS sent down from the server never runs at all. However, the jQuery AJAX handler does invoke the comet failure function—which is designed to deal with connection errors, not JS parse errors. The reaction to a comet request's failure is to try again (I think in 10s?), so we try another comet request. However, it's the JS that comes from the server that lets us know what the latest update we've seen from the server is. Since the JS didn't run, our version didn't update, which means the comet sees that we're out of date and sends us the original update as well as anything else that has happened since then! Net-net, we get the bad JS again, and the cycle starts over.
We may be able to update the failure handler to look for what error jQuery tells us it got—but the problem is that our AJAX stuff is designed to work with jQuery, YUI, and one or two other libraries, which means we'd have to make sure they all reported a JS parse error the same way, or that we implemented handling for all the different ways in the failure callback. Either way, things get pretty nasty.
Hope that sheds some light onto why this is happening, despite not offering an immediate solution. Thanks for bringing it up; this has bit me before (though not since we switched to using events+JSON to send things down to the client as a matter of course), and it can be quite frustrating. Thanks, Antonio
Okay, just investigated this a bit more. We actually do script execution in YUI and Ext in our own custom way, which doesn't report errors but also shouldn't prevent the success handler from running. This means only in the jquery case do we end up in the situation of infinitely accumulating updates when an error happens.
That's good, because it means the special case handling for that error can simply look for the jquery error parameter and if it's absent we can assume we're going to proceed as normal. PR Coming Soon™.
An update here: this is harder than it looked! Because script execution is typically done using something like jQuery's globalEval, which uses script injection, errors in the script are almost impossible to deal with, except possibly by hooking into window.onerror… More to come as I get a chance to look at it more deeply.