Firebug Losing Marbles - javascript

I've noticed recently firebug is starting to throw javascript errors about code that it hasn't before. Such as $ is not defined and also errors with Jquery and processingjs core, which i'm assuming is error free.
Anyone else getting this, and should I just ignore it?

should I just ignore it?
Probably not: Errors in reference libraries like jQuery often stem from their functions being called with incorrect parameters.
It's impossible to say more without details, but it is definitely worth investigating why this happens.

Related

Set up javascript on vscode properly

I'm having trouble setting up a JavaScript project in my VSCode.
What I currently have technically "works", but it wont do proper syntax highlighting and syntax error detection. For example, the following code on a fresh file won't show any error:
woosh();
The thing is, there is no function called woosh anywhere (not even in other files). The error is caught only when I try to actually run this code. Does anyone know what I might have done wrong?
VSCode does not highlight JS mistakes like this, because it's not a syntax error; The code above would cause a runtime error.
Install addons like eslint, jshint. If that doesn't work then I recommend learning typescript. It's a superset of javascript with strict type checking. It helps us to catch silly bugs like these.

How to catch typos errors in VIM for EmberJS (Javascript)

I am starting to learn EmberJS/JS/VIM . I was going through the official ToDoMVC guide for EmberJS, and I ran into typos errors that was really really hard to detect with the "eyes" and the browser really didn't help in this case at all. So, can you please suggest me what tools or techniques that can be used to detect these types of typos errors?
For example:
### todo_controller should've been todos_controller
<script src="js/todo_controller.js"></script>
### catching the end of { } closed scoping
### typo within a model js "property"
inflection: function() {
var remaining = this.get('remaining');
return remaining === 1 ? 'todo' : 'todos';
}.proprety('remaining')
EDIT;
Yes, I did search before posting here. The first was this website, and the comments here basically suggest DreamWeaver Frustration with Typos.
I searched SO itself (through google), and there was Is there a way to catch typos. I did find out there is something called LINT, but it dealt with coffeescript.
I did find out ember.vim as you pointed out before, but as you see the README in the github profile, i believe it strictly wants you to follow the layout as prescribed. It may be a good thing in future, but right now, I wanted to just stick with what the official ToDoMVC way. I am just beginning to get a hang of hjkl, so I do not think I can makes changes to it to fit my way. Also, second point, is the layout format it supports is Ember-AppKit which has been deprecated. SO I am having doubts if I should follow the layout pattern itself.
And all of them didn't particularly address what I am asking. In the todo_controller typo above, the browser didn't throw any sort of errors. I am using FF/Firebug, and on the Console, it only showed the message about Ember loading, and no errors at all. It took me a while to see that typo. The second one did throw errors, but typos are a hard thing to discover in VIM. The third one, took a bit of time, and there were others. These don't throw errors at all. I am used to PHP, and while there is no direct showing of errors as in Android, I am finding Javascript typo hunting to be very hard.
it took me like 3 looks before I saw your typo.
Set your browser to pause on exceptions (sometimes pause on Caught Exceptions). It's been one of the quickest ways I've found to track down a weird bug. In this case I'm sure you were getting Uncaught TypeError: undefined is not a function....
Don't take this the wrong way, but did you try to search before asking? There has been, for quite a while now, a plugin for Vim that has syntax highlighting improvements.
https://github.com/dsawardekar/ember.vim
Beyond that plugin, you could try writing your own solution. I haven't tried, but I doubt there is anything out there that will pick up spelling errors for Ember...
I use JSLint for SublimeText 3, which lints as you code so you get a live update of any potential bugs. Kinda nice. Here's something similar for Vim: https://github.com/hallettj/jslint.vim
As #kingpin2k suggests, you should really learn how to use your browser tools. The big three are just jam-packed full with development and debug tools. 9 times out of 10 it gives you the line and column of the error, and you can set breakpoints within the code to watch it execute in-context. And, that is really just the tip of the iceberg in terms of how detailed you can get with debugging in-browser.

Third party JavaScript - good idea to use try catch?

I am developing a third party JavaScript widget that will be included by users on their applications/blogs. I have good tests around the library, but I am afraid that if despite that if some syntax error sneaks through and cause the other scripts on the user's application to stop loading.
So - to prevent this from happening, is it a good idea to surround my entire widget code in a try/catch like this?
try {
// my library
} catch(e) {
// notify me about the error
}
Here is a good common approach to what try-catch blocks are used for. If you can catch an exception and do something with that exception then go ahead and catch it. For example, BadHtmlException or something similar is an exception you can catch to provide user with feedback that you should fix the HTML and try again.
There are types of exceptions that there is no action that can be done. For example, the application was configured incorrectly with a bad user/password. This should be a critical error and should be push all the way up to the application. Possibly an exception that might not make sense to the user.
So what am I suggesting? I am suggesting don't wrap anything in a try-catch unless you know there will be that exception thrown. If there is a bug or exception, the person using your code should see it and report it as an issue. You really can't spend all your time going through possible issues that may or may not be your code.
Finally, you should write unit tests and make sure each part of your library is well tested before each release. Doing this will make sure that future releases don't break anything.
What you could do, is have a try/catch block around the code, putting a console.log() call in the catch block. This way, consumer's code will still run, but when debugging, they'll see that something went wrong within your library and notify you.

Ajax problem using MooTools/jQuery - p.onStatusChange is not a function

I get the following error in firebug in Firefox 3 with both MooTools and jQuery:
"p.onStatusChange is not a function".
I've noticed this error frequently in firebug since one of the latest updates of FF3. However, it has started appearing with code that hasn't been changed in some time and that was not reporting errors previously. The errors happens when ajax results are returned. It shows up in different applications that use separate javascript libraries, MooTools and jQuery.
Does anyone have any idea why these errors are appearing? My intuition tells me that it is something in Firefox that changed, but I can't find any information online currently. The ajax calls still work fine, but I am wary of just going with my intuition and leaving script errors in my code.
Thanks,
Jason
I get it in tabBrowser instead:
chrome://browser/content/tabbrowser.xml
(4) errors occur:
p.onStatusChange
p.onProgressChange
p.onStateChange
p.onSecurityChange
What I found was that the add-on "PDF Download" was causing these errors. The best way for me to check was to go to a page that produced the errors, turn off all the add-ons, and turn them on one-by-one (starting with Firebug). Instead of going one-by-one, I actually turned them on in lots of 3 to help identify the problem sooner.
Here is the reference for the function NsIDownloadProgressListener. It looks like it has been deprecated.

Using Elmah with jQuery?

I am using jQuery to invoke page methods for my AJAX calls using $.Ajax. This works very well, and is very lightweight. However, I have noticed that when an exception is thrown from the .NET code, Elmah just logs it as a File Not Found exception, or will not log anything at all, rather than logging the actual exception that was thrown. Is there a way to get Elmah to pick up these exceptions? Do they need to be caught/rethrown? I'm sure it has something to do with the error handling in the JavaScript file, but I don't know where to go from there.
I'm pretty certain that if ELMAH won't log properly in this senario without some modification.
May be worth asking the question here.
link text
Atif Aziz is generally quick to answer the questions

Categories