To Err is Human, Thorough Error Reporting Divine

Tuesday April 15th 2008, 8:37 pm Printer Friendly Version
Filed under:Firefox
Posted By: Matt

Update: Eric Shepherd already has some great documentation of the new JavaScript error reporting regime up on MDC.

Update: Note also that most errors will be reported by default, so the pref only turns on a few additional cases. Read the MDC article for full details.

I’ve been doing a lot of JavaScript development as part of my work on Prism, and I noticed a few weeks ago that a lot of errors I was used to seeing in the console weren’t showing up anymore. Unsure of the cause, I first took the expedient route of sprinkling my code with dump() statements whenever I had to track down a problem. This is tedious and time-consuming, however, and after a while I got fed up and (with Shaver’s prodding) spent some time trawling through the JS error reporting code trying to figure out what had broken.

Luckily for me, Sergey Yanovich noticed my incessant whinging on IRC and pointed me at bug 393627. It seems that some changes had been made to a JavaScript component that threw an exception that was expected, caught and managed in C++ code. Nonetheless, an error was being displayed in the console by XPConnect, so a patch was committed to suppress reporting of exceptions in these circumstances. Unfortunately this had the side effect of turning off useful and desirable reporting for a huge swath of errors.

A few weeks and 21871 bugs later found us embroiled in a heated discussion in the comments of bug 415498. The problem, it transpires, is a tricky one, as Ben Turner explained:

Ok, so here’s our basic problem: Some folks think that throwing exceptions is a perfectly valid way to communicate with C++, others try to avoid any unhandled exceptions and want to know if any make it back to C++. There is no way to consolidate those opinions, and we’ve argued back and forth about it many times already. A functional Components.resultCode might make this situation better, but that’s been broken for far too long to hope we’ll see it fixed in the next week.

Ben’s solution was to implement a preference, dom.report_all_js_exceptions, that turns on the verbose error reporting so vital to JavaScript developers. So even if you just skimmed the last few paragraphs, please pay attention because if you code in JavaScript in Firefox 3 you want to know this. Grab yourself a recent trunk (Ben says the fix landed last Wednesday or so). Set that preference. Watch your error reporting woes vanish before your eyes. There should be real documentation on this soon, but in the meantime hopefully this information will be of use to some.


 

AllPeers File Sharing



AddThis Feed Button



Creative Commons License
This work is licensed under a Creative Commons License
Conestoga Street Wordpress Theme by Theron Parlin