Jump to content

Verbose javascript error messages? Debugger?


vailixi

Recommended Posts

Is there a way to get verbose errors whilst debugging javascript? I had written an application in C++ and I'm porting it to javascript the only thing is javascript doesn't like some of the strings and just wants to throw an error. I looked up how to remove non-English characters a bunch of different ways. Not really sure what I'm doing wrong. It just says SyntaxError: missing ; before statement
It links the line and thats all well and good but it's a string array with about 14,000 strings and where that missing ; is supposed to be I'm really not sure.
 
Is there an IDE for javascript that will give me better error messages or some bash-fu I can run on the javascript files to remove the array elements that are not compatible?
 
Also is there a maximum array size in javascript?
Link to comment
Share on other sites

I assume that when you say that it's an array of strings you have something like

var messages=[
    "message 1",
    "message 2",
    "message 3"
];

If it is then the chances are that it's not so much an error caused by the missing semi-colon as a string containing an unescaped quote that's terminating the string too early.

I don't think a debugger would help much as it is an error at the compiling stage. Have you tried running jshint against the code? It may narrow down the error a bit more.

If jshint doesn't help you track down the source of the problem you could always fall back on a good old binary search to find the source of your problem.  Simply comment out the first half of your strings in the array and see if it the error goes away,  if it does you know the error is in the first 7,000 strings, if it doesn't you know it's in the last 7,000 strings. Then repeat the process on the block of 7,000 strings with the error in to narrow it down to 3,500 strings, repeat again to narrow it down to 1,750 strings, and keep going till you've narrowed it down to a number of strings that you can actually look at manually.

Link to comment
Share on other sites

Don't forget your quotes around your strings. I know it's standard to C++ and Javascript, but I work with a guy who beat his head against the desk for 6 hours looking for the source of the missing ; before statement, and it turned out that he hadn't put quotes around his string.

As far as debugging, I haven't done with just javascript, but when mixing PHP, Javascript, and HTML, I like to use the Firebug extension for Firefox. I've been able to track down some issues that just don't show up otherwise, and it especially helps with the javascript, assuming it's in a .js file and NOT in <script> tags.

That's my .02 cents, YMMV, and I approve this message.

Edited by neoknight88
Link to comment
Share on other sites

If using Opera or Chrome, hit CTRL+Shift + J to open the console. you can, on a blank tab/local page, copy and paste actual snippets of code and run it directly in the console, and it will come back with errors. you can also load a local page, and set breakpoints on specific sections where the errors happen to look into it further, jump over items like a debugger, etc. In the sources tab you can see the loaded files if calling in external js files, and also show cleaned up code of minified imported code if combining with things like minified jquery. This would be my suggestion on where to start with debugging it though.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...