Chad
Chad

Reputation: 432

What to do about infrequent (seemingly) random JavaScript errors in production?

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:

Upvotes: 4

Views: 730

Answers (2)

jfriend00
jfriend00

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:

  1. What percentage of page views are being affected?
  2. What are the specific exceptions and what trouble do they cause?
  3. How important is that trouble to your business.
  4. How much time will it take to identify and fix these and how does the business importance of that compare with other projects on your plate?

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

cchamberlain
cchamberlain

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

Related Questions