Simple Cloud – Error Handling Not Portable

In my previous article about the lack of exceptions in PHP libraries, I came across an inconsistency with Simple Cloud‘s API (now known as the Zend_Cloud component) between file storage adapters.

The issue is that Windows Azure and Nirvanix storage adapters will always throw an exception on an unsuccessful attempt (checked against the API response) whereas Amazon S3 adapter will return true/false (checked against API response) or an exception (some other underlying client error) therefore breaking portability. You could add an explicit check for false but that isn’t obvious. There’s also no use of the @throws tag in the docblock making this even less obvious.

I’ve only checked this against the file storage part of Simple Cloud but I seem to remember the same no-exception issue being in the Amazon SQS API as well.

Zend\Service\Amazon\S3.php – putObject()

$response = $this->_makeRequest('PUT', $object, null, $headers, $data);

// Check the MD5 Etag returned by S3 against and MD5 of the buffer
if ($response->getStatus() == 200) {
    // It is escaped by double quotes for some reason
    $etag = str_replace('"', '', $response->getHeader('Etag'));

    if (is_resource($data) || $etag == md5($data)) {
        return true;

return false;

Zend\Service\WindowsAzure\Storage\Blob.php – putBlob() to putBlobData()

// Perform request
$response = $this->_performRequest($resourceName, '', Zend_Http_Client::PUT, $headers, false, $data, Zend_Service_WindowsAzure_Storage::RESOURCE_BLOB, Zend_Service_WindowsAzure_Credentials_CredentialsAbstract::PERMISSION_WRITE);
if ($response->isSuccessful()) {
    //isSuccessful checks for 2xx or 1xx status code
    return new Zend_Service_WindowsAzure_Storage_BlobInstance();
    //stripped code for blog article
} else {
    throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));

Another issue is that the docblock for Zend\Cloud\StorageService\Adapter\S3.php storeItem() has “@return void” which isn’t the case (most of the other methods appear to be this way as well).

Related bug report without attention:

This entry was posted in Amazon Web Services, Cloud, PHP, Zend Framework and tagged , , , , . Bookmark the permalink.

One Response to Simple Cloud – Error Handling Not Portable

  1. Pingback: Lack of Exceptions in PHP Libraries | Rob Olmos

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>