30. Oktober 2012

Webkit: Error Code -999 Surprise

Recently I was programming with WebKit. I am trying to handle all errors, log them appropriately and discovered an error, that should not happen. If WebKit navigates to a URL and the navigation is cancelled by another navigation, then WebKit throws an error. A pseudo error. Quite a normal approach.

It would be nice, if my error handler could distinguish between real errors and pseudo error  Fortunately the error handler gets an error code. The code is -999. A strange number. Could it be, that there are 1000 error cases and just by chance NAVIGATION_CANCELLED is number -999. Probably not.

Stepping a bit closer to the error source, we discover in WebFrame.cpp:

ResourceError WebFrame::cancelledError(const ResourceRequest& request)
{
    // FIXME: Need ChickenCat to include CFNetwork/CFURLError.h to get these values
    // Alternatively, we could create our own error domain/codes.
    return ResourceError(String(WebURLErrorDomain), -999, request.url().string(), String());
}

Looks like -999 is a hack. Other error condition have "real" codes:

ResourceError WebFrame::blockedError(const ResourceRequest& request)
{
    // FIXME: Need to implement the String descriptions for errors in the WebKitErrorDomain and have them localized
    return ResourceError(String(WebKitErrorDomain), WebKitErrorCannotUseRestrictedPort, request.url().string(), String());
}


Happenz. But still a surprise, because...

THIS IS THE MAJOR OPEN SOURCE BROWSER ENGINE, THAT THE WORLD USES ON A BILLION DEVICES.

WTF

_happy_cooking_with_water()