The third line here sometimes causes a crash with "runtime error 18: Type Mismatch":
if( rsp = invalid ) fatal_connection_error()
xml = CreateObject("roXMLElement")
if not xml.Parse(rsp) then
The rsp variable might contain a string or it might contain invalid. The string might not be valid xml, sure, but I don't think that the error in that case would be a type mismatch. The value might be invalid, but in that case the fatal_connection_error() call will prevent processing reaching the line with the type mismatch.
So it must be xml.Parse that is the mismatch. xml must contain a thing that is not an roXMLElement. Most likely it's invalid.
That implies that Brightscript apps need to always check for allocation errors in CreateObject(). We can do that, and I guess we will, but all we'll do with the failure is to shut down with a prettier error screen than a crash will give you.
Ideas welcome.