Reputation: 432
I'm going to come clean and admit that out of sheer ignorance I've been flying blind with my websites until recently when I deployed a site with Elmah (an error logging facility for ASP.NET) and a controller on the server to send all uncaught JavaScript exceptions. This was an eyeopening experience to say the least.
One of my sites is getting about 150-200 visitors a day. About once a day I get an Elmah JavaScript stacktrace similar to this one:
CCS.Exceptions.JavaScriptException: Unspecified error.: at document path
'http://www.*******.com/*****'. at anonymous('Unspecified error.',
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/jquery-ui.min.js', '5')
at anonymous()
I'm relatively new to JavaScript and web development in general so I'd appreciate some advice:
How should I go about getting to the root cause of problems like this? Any advice for debugging problems in production (specifically JavaScript)?
Where would you rank this on the scale of importance? I realize that question is almost impossible to answer without knowing everything on my plate. But what I'm hoping for is advice for prioritizing this kind of stuff. Is my hair on fire? Or, "Meh, this is really common and given all of the browsers and OSes these days this kind of thing is bound to happen."
Upvotes: 4
Views: 730
Reputation: 707696
The chances are pretty good that each one of these exceptions is a web page that is NOT working as designed. In order to understand that priority, you need to understand the following:
In general, you won't know the answers to any of these questions without further research so you'll either have to decide that all exceptions that aren't fully understood are a bad thing and should at least be understood.
Or, you'll have to decide to launch an investigative project to get more information related to these questions and then decide whether to fix it or not.
Or, you'll have to decide that you just havne't heard enough reports of problems with your web site to warrant any further investigation (I personally don't like this option because you're guessing that it doesn't matter).
Without knowing much detail about your business, my recommendation would be to budget and plan an investigation project to learn where these errors are coming from and understand their impact on the usability of the site. Making decisions with some data in hand is way better than guessing.
As for debugging, you ultimately need to find out which line of code is triggering the exception. You also may want to record what browser configuration is generating the error (in case it's a browser version related issue). You can start by understand what each piece of information in your stacktrace report means and what it tells you and then find out if you can enable more detailed tracking of the exceptions in the Elmah system. If not and you can figure out approximately where the error's are coming from, you can implement your own exception logging that might be able to capture additional information.
You may also browse through any trouble ticket reports you have on the site because there may be some internal or external reports of problems with the site that might be correlated with these exceptions.
Upvotes: 1
Reputation: 17966
JavaScript errors can be difficult to get to the bottom of. The best thing you can do is ensure that your JavaScript is written cleanly and put everything into namespaces to keep your window object as clean as possible and avoid variable hoisting which is a common issue when JavaScript libraries get unruly. Below is the preferred namespace pattern that I use across the board -
/* Namespace pattern */
var myAppNamespace = myAppNamespace || {};
(function(ns) {
ns.doSomething = function() {
// enter code here
};
}(myAppNamespace));
/* Usage */
myAppNamespace.doSomething();
Upvotes: 0