views:

222

answers:

5

I have a Rails application, and when I have Javascript errors they are not showing in the Firebug console. I have 'Show javascript errors' and 'Show javascript warnings' selected.

When I insert javascript errors in a basic html file, the errors show as expected.

In the javascript of the Rails app, it only shows errors in rare cases. For example i can insert nonsense like:

dfghaefb;

and no error is shown in Firebug. But if i insert a space in there Firebug does show the error:

dfgh aefb;

Any ideas? This is driving me nuts.

UPDATE: Pumbaa80 was right, it's syntax vs runtime.

So I set up onerror:

onerror=errorHandler;
var error="";

 function errorHandler(errMessage,url,line){
  error="There is an error at this page.\n";
  error+="Error: " + errMessage+ "\n";
  error+="URL: " + url + "\n";
  error+="Line: " + line + "\n\n";
  error+="Click OK to continue viewing this page,\n";
  alert(error);
  return true;
 }

And I have a method with an error:

function initForm() {
    asdfs;
}

And it works when I call it outside of a method:

initForm();

but not in this case:

document.observe('dom:loaded', function() {

    initForm();
}); 

Why is that?

A: 

Did you let the page load completely? I have a rails app running in front of me right now with firebug on and i entered dfghaefb; and yes it does throw an error!

 ReferenceError: dfghaefb is not defined {  message="dfghaefb is not defined",  more...}

Running Firefox 3.6.3, Firebug 1.5.3 and MacOSX 10.5.6 :)

Shripad K
A: 

This may appear to be obvious, but be sure you wrap your inline JS using

<script type="text/javascript"> code </script>

Otherwise FireBug won't look at it at all.

Andy
A: 

I had the same, it wasn't showing anything and it was driving me crazy for ages, even if i had "Show javascript errors" in the console tab selected, it seems that it started working after I did "Enable all panels".

jhexp
A: 

These kinds of problems cannot be answered without a test case.

johnjbarton
A: 
dfghaefb;

produces a run-time error. Those errors may be suppressed by putting an onerror handler on the window or by trapping them in a try/catch in some way. In that case, Firebug won't show anything.

In contrast,

dfgh aefb;

is a syntax error, which is shown in the error console, regardless of try/catch and onerror.

Pumbaa80