Tuesday, December 15, 2009

Hunting Down the Bugs – TwCLI on Chrome for Linux Beta

This is the first post of a new series, looking at some of the odder
bugs encountered while developing for the expanding Web, no matter how basic a bug it may be.


Thanks to twitter user @paperfairy,
a bug was discovered on my Command Line Twitter Client, href="http://twcli.koneko-chan.net/" rel="me">TwCLI.

For some reason, when
submitting a command in Chrome for Linux, the page would simply refresh, and the command would never be
sent.  At first, I had no possible way to track down this bug.  I didn’t have a linux box
(with a GUI, anyway) so I simply told him that it was unfortunate, but it’d have to stay a bug. 
Until a rel="nofollow">recent post on lifehacker brought my attention to href="http://lifehacker.com/5195999/portable-ubuntu-runs-ubuntu-inside-windows">Portable Ubuntu.
I immediately installed it, opened up the Chrome website in Firiefox, installed Chrome Beta, and headed over
to TwCLI to see what was amiss.

Of course, it was a single line in a detection script to
send Geo-Data to Twitter (as long as the user approved it, of course):

style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom:
4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%;
padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr;
max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right:
silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
else             style="color: #0000ff">if(google.gears) {




This
single line was throwing an exception I hadn’t encountered in other browsers – Google wasn’t defined. 
Oddly, I thought it would handle that properly, since google wasn’t defined, it would just skip over it, but
instead it threw an error and halted all further javascript code.



The
fix was simpler than tracking down the bug, I simply had to add this to the start of the javascript code:



style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom:
4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%;
padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr;
max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right:
silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt;
border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px;
font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none;
color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">

try{ if(!google)
{ google = 0; } } catch(err) { google = 0; }






And
voila, I had both a check for google, and a catch if it decided to throw errors while checking for it.



Whether
this is a Chrome bug or not, I don’t know – I simply don’t know enough about JavaScript in order to say so
either way.  But, are undefined variables supposed to throw errors, or are they simply supposed to
return false?

No comments:

Post a Comment