PhotoBook 1.0.2 is out!
Hurray! I hope you are excited as me!
Sorry for Yet Another Bug Fix Release, but I needed to get some things fixed, and there are a few new minor features in there.
One bug in particular bugged the hell out of me. The “back” button on your browser has been remotely disabled to ensure you will listen to this pointless story.
A very small number of users were either getting an Unknown error when logging in, or were getting stuck on loading screens. This small subset users just happened to include people reviewing apps for facebook, which is why PhotoBook is not currently in the Application Directory
It was truly a bug like Steven Frank writes about.
I, of course, could not reproduce it myself, but a patient user with the problem offered to help track it down (thanks!)
Basically, I make a request to facebook using their REST API (with their awesome pseudo-SQL language FQL) and it sends back the response in XML. I then parse this XML with NSXMLDocument.
The “unknown error” indicates the NSXMLDocument is nil, and somehow no error from the download, facebook, or the NSXMLDocument was returned.
So, going down the list, I first assumed the FQL query was bad (maybe some object used in the query was returning nil and facebook freaked out and returned no data). Nope, the query looks fine.
Next, I thought the problem might be on facebook’s side, and it was returning no data. Nope, it returns something that looks like XML.
So, I guess the XML might be invalid. I get a sample response from the user (as a NSString) and feed it into a NSXMLDocument. It is parsed fine.
Maybe there is something wrong with my download code? I stick the data hidden on a server, and try to download it with the same code. Works fine, and is parsed correctly.
Finally, through some trickery, I get facebook’s servers to return the same data. This data looks like the same, but is actually a few bytes longer. I feed it into NSXMLDocument, and yay! It returns nil, and it does not even set the NSError object I pass to it (even stranger).
So, finally, I set the option NSXMLDocumentTidyXML and everything works fine.
I still have no idea why (a)facebook is returning a few extra bytes or (b)NSXMLDocument returns nil without setting the error object I pass to it with anything. But whatever. I guess the lesson is never trust any data you do not have complete control over. Programming 101, but whatever.
I have had plenty of other problems with trusting data too much (FQL randomly not returning everything I ask from it, queries that are too long for GET and return 414-Request URI too long). It is still loads of fun.
I promise some interesting cocoa posts soon, and lots of cool features for PhotoBook 1.1.