views:

386

answers:

10

I'm writing an app which for various reasons involves Internet Explorer (IE7, for the record), ActiveX controls, and a heroic amount of JavaScript, which is spread across multiple .js includes.

One of our remote testers is experiencing an error message and IE's error message says something to the effect of:

Line: 719
Char: 5
Error: Unspecified Error
Code: 0
URL: (the URL of the machine)

There's only one JavaScript file which has over 719 lines and line 719 is a blank line (in this case).

None of the HTML or other files involved in the project have 719 or more lines, but the resulting HTML (it's sort of a server-side-include thing), at least as IE shows from "View Source" does have 719 or more lines - but line 719 (in this case) is a closing table row tag (no JavaScript, in other words).

The results of "View Generated Source" is only 310 lines in this case.

I would imagine that it could possibly be that the entire page, with the contents of the JavaScript files represented inline with the rest of the HTML could be where the error is referring to but I don't know any good way to view what that would be,

So, given a JavaScript error from Internet Explorer where the line number is the only hint but the page is actually spread across multiple files?

UPDATE: The issue is exacerbated by the fact that the user experiencing this is remote and for various network reasons, debugging it using something like Visual Studio 2008 (which has awesome JavaScript debugging, by the way) is impossible. I'm limited to having one of us look at the source to try and figure out what line of code it's crapping out on.

UPDATE 2: The real answer (as accepted below) seems to be "no, not really". For what it's worth though, Robert J. Walker's bit about it being off by one did get me pointed in the right direction as I think it was the offending line. But since that's not really what I'd call good or reliable (IE's fault, not Robert J. Walker's fault) I'm going to accept the "no, not really" answer. I'm not sure if this is proper SO etiquette. Please let me know if it's not via the comments.

+3  A: 

The best way I found to debug javascript was to add several Response.Write() or alert message near the place i believed the code broke. The write or alert that doesn't show is closest to the problematic area of the code.

I did it this way because I haven't found an easier way.

Update: If you use this method of debugging you can use the writes/alerts to the contents of variables as well.

Matt R
Good old print statement debugging. Takes me back. :)
Bill the Lizard
console.log is just print debugging that prints to a different buffer. :D
eyelidlessness
+1  A: 

Try Firebug. I is available for IE: http://getfirebug.com/lite.html

Zombies
"View Source" will return the source of the document - not any javascript files included with script src="blah"
matt b
This project kills Firebug for IE (I've tried it), probably due to the ActiveX involvement.
Schnapple
+1  A: 

Have you checked whether this error is also present in Firefox using Firebug? That would be my first step in attempting to figure out where this error is occurring.

If it isn't present in Firefox, then I would progress to enabling script debugging in IE.

steve_c
The ActiveX involvement negates being able to try this in Firefox.
Schnapple
OK, so then I would enable script debugging in IE. To do this:tools > Internet Options -> Advanced -> uncheck 'Disable Script Debugging (Internet Explorer)This will allow you to break into a debugger (such as VS.NET) and will highlight the line where the error occurs.
steve_c
Yeah, and this is what I do locally, but the user/tester that's having this issue does not have any development software so they can't debug nor can I debug remotely.
Schnapple
A: 

I use Web Development Helper

sebastian
+3  A: 

The web developer toolbar in IE7 can give you a rendered source view.

View > Source > Dom (Page)

This might be more accurate when you consider the line numbers provided by IE for script errors.

EndangeredMassa
this looks useful - I didn't know the developer toolbar had this option before - thanks!
matt b
This is pretty handy - but doesn't help me in this instance I'm afraid. It produces source code that doesn't have enough lines and doesn't include JavaScript inline (if that's the issue). The crux of this issue is that the only thing I have to go on is a line number which is apparently useless.
Schnapple
Sorry that it didn't help.
EndangeredMassa
+1  A: 

My only advice: don't use IE for debugging like this. It's the absolute worst of the mainstream browsers: I try to use Firefox (with Firebug) or Chrome/Safari to handle most issues.

If you absolutely have to use IE, install the IE Developer Toolbar (which doesn't seem to help much with JavaScript errors), and/or install the Script Debugger

matt b
but not using IE doesn't really help you for IE-specific javascript errors, does it?
matt lohkamp
+2  A: 

By installing firebug lite on your server for that page:

<script type='text/javascript' 
    src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'&gt;
</script>

you can log to a virtual console with,

firebug.d.console.log("stuff and things")
firebug.d.console.dir( {returnedObject:["404", "Object Not Found"]} )

and ask your remote tester to get more details for you by pressing F12.

I sort of suspect there's an unterminated string or an unmatched parenthesis or bracket out there.

dlamblin
+5  A: 

In short. Not really. Try finding the error in FF first, and if that fails, you can get an almost as good debugger with Visual Web Developer. Debugging IE just sucks for the most part.

noah
I was gonna say it if you weren't - it feels wrong to say, "no, you can't do that," but in IE's case... sometimes you've gotta say it.
matt lohkamp
+2  A: 

Nope, there isn't a way to make the built-in exception message suck less.

Instead you'll need to use a debugger with IE. The best tutorial I've found for this is here:

http://www.berniecode.com/blog/2007/03/08/how-to-debug-javascript-with-visual-web-developer-express/

Follow these instructions and when an error or exception occurs you will be shown the exact line in the correct file. You'll also see the value of variables in the current scope and you can setup "watched" items to help you debug.

Aside from that, if you need logging and CSS Cascade inspection like Firebug I've had good results with DebugBar and JSCompanion:

http://www.debugbar.com/ http://www.my-debugbar.com/wiki/CompanionJS/HomePage

morganizeit
+3  A: 

Tip: I find that many IE error message line numbers are off by one!

Robert J. Walker