I thought I'd write this short article about how we fixed a nasty bug at Browserling together with my friend James Halliday yesterday.
Long story short we were testing Browserling in the latest FireFox and we got this nasty exception that said:
uncaught exception: [object Object]
Here's how it looked in Firebug:
FireBug didn't show the line number where it was thrown from and we couldn't find a way how to make it show the stack trace. We tried stepping through the code and setting breakpoints at some potential locations but didn't get us anywhere.
We were stuck and annoyed.
So we came up with a very hacky Perl one-liner that appends a console.log
to almost every function definition:
perl -i -pe 's/function.*{$/$&."\n console.log($.);"/e' bundle.js
What this one-liner does is it finds all lines that have string function
in them and that end with {
and appends a console.log
with the current line number to the beginning of the function.
For example, this code piece:
function foo (x) { return 50/x; }
Gets rewritten as:
function foo (x) { console.log(1); return 50/x; }
Our thinking was that we should get the line number of the last function call before the exception was thrown or some function call nearby.
And it worked!
We refreshed Browserling and we got an awesome trace with lots of line numbers followed by the same uncaught exception error:
... 11248 11157 11257 11147 uncaught exception: [object Object]
Here's how it looked in FireBug:
Next we checked the line 11147 in the original file (line 11914 in the updated file because the one-liner offsets line numbers) and we found the exception that we were looking for:
error = function (m) { // Call error when something is wrong. throw { name: 'SyntaxError', message: m, at: at, text: text }; },
A fix quickly followed and we got Browserling working in the latest FireFox! Until next time.