ZF-5949: When connectivity is down, it fails with fatal non-object error

Description

In short: If network connectivity is down after you got Zend_Gdata_Gapps service with valid authentication credentials, then the next Google request fails and throws a fatal error rather than a nice Zend exception.

That can happen e.g. in batch processing, when you use Zend_Gdata_Gapps over several actions, and suddenly your comms go down.

How to duplicate the problem: <?php set_include_path( get_include_path() . PATH_SEPARATOR . dirname(__FILE__). "/../library" ); require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Gapps'); $client = Zend_Gdata_ClientLogin::getHttpClient("GOOGLE_SERVICE_EMAIL", "GOOGLE_SERVICE_PASS", Zend_Gdata_Gapps::AUTH_SERVICE_NAME); echo "\nAuthenticated ok. NOW DISCONNECT the network cable"; sleep( 20 ); $service = new Zend_Gdata_Gapps($client, "GOOGLE_DOMAIN"); $service->createUser( 'sleepy.smallelephant', 'Small Elephant', 'Sleepy', 'very secret password', null ); ?>

Trace: Fatal error: Call to a member function getBody() on a non-object in /Users/peterk/google.mytbwa.com/trunk/google_gateway/library/Zend/Gdata/Gapps.php on line 151

Call Stack: 0.0051 239216 1. {main}() /Users/peterk/google.mytbwa.com/trunk/google_gateway/action/process.php:0 0.0901 3633944 2. process_action_set_status() /Users/peterk/google.mytbwa.com/trunk/google_gateway/action/process.php:745 0.0901 3634496 3. process_action() /Users/peterk/google.mytbwa.com/trunk/google_gateway/action/process.php:307 10.0916 3643920 4. Zend_Gdata_Gapps->retrieveUser() /Users/peterk/google.mytbwa.com/trunk/google_gateway/action/process.php:427 10.0952 3761512 5. Zend_Gdata_Gapps->getUserEntry() /Users/peterk/google.mytbwa.com/trunk/google_gateway/library/Zend/Gdata/Gapps.php:754 10.0953 3761784 6. Zend_Gdata->getEntry() /Users/peterk/google.mytbwa.com/trunk/google_gateway/library/Zend/Gdata/Gapps.php:465 10.0953 3762072 7. Zend_Gdata_App->getEntry() /Users/peterk/google.mytbwa.com/trunk/google_gateway/library/Zend/Gdata.php:186 10.0953 3762072 8. Zend_Gdata_App->importUrl() /Users/peterk/google.mytbwa.com/trunk/google_gateway/library/Zend/Gdata/App.php:219 10.0953 3763024 9. Zend_Gdata_Gapps->get() /Users/peterk/google.mytbwa.com/trunk/google_gateway/library/Zend/Gdata/App.php:718 10.1105 4222608 10. Zend_Gdata_Gapps::throwServiceExceptionIfDetected() /Users/peterk/google.mytbwa.com/trunk/google_gateway/library/Zend/Gdata/Gapps.php:205

Proposed solution: In library/Zend/Gdata/Gapps.php modify throwServiceExceptionIfDetected($e) to use something like following: $response= $e->getResponse(); if( $response ) { $error = new Zend_Gdata_Gapps_ServiceException(); $error->importFromString( $response->getBody() ); //var_dump(debug_backtrace()); //debug_print_backtrace(); throw $error; } else { throw new Exception( "Google connection is down or some other serious error." ); }

This is in version 1.7.4 but throwServiceExceptionIfDetected() is same in 1.7.6 so most likely there's the same problem in 1.7.6 and the fix should work for 1.7.6 too.

I've signed the contributor's agreement so it's OK for you to use any of the above. Thx

Comments

Patch sent to [~jhartmann] for review:

http://codereview.appspot.com/24079

Committed to trunk as r14612. Committed to release-1.7 as r14613. Marking as fixed as of the next mini release.

commit e882d1eb739c7a77dfbaa28bcea7254bae715ef6
Author: tjohns 
Date:   Thu Apr 2 22:52:29 2009 +0000

    ZF-5949: Update Zend_Gdata_Gapps to throw an exception (rather than a fatal
    error) when connectivity is lost.
    
    Review URL: http://codereview.appspot.com/24079
    
    git-svn-id: http://framework.zend.com/svn/framework/… 44c647ce-9c0f-0410-b52a-842ac1e357ba

commit ac3147eb8d9be1928ffb2bbfb4f1ef3586105cf2
Author: tjohns 
Date:   Thu Apr 2 23:04:12 2009 +0000

    Merging r14612 from trunk to release-1.7.
    
    ZF-5949: Update Zend_Gdata_Gapps to throw an exception (rather than a fatal
    error) when connectivity is lost.
    
    Review URL: http://codereview.appspot.com/24079
    
    git-svn-id: http://framework.zend.com/svn/framework/… 44c647ce-9c0f-0410-b52a-842ac1e357ba