xxxx replace private information:

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /home/xxxxx/public_html/sites/all/modules/twitter/twitter.inc:477
Stack trace:
#0 /home/xxxxxxx/public_html/sites/all/modules/twitter/twitter.inc(477): SimpleXMLElement->__construct('')
#1 /home/xxxxxx/public_html/sites/all/modules/twitter/twitter.inc(101): _twitter_convert_xml_to_array(NULL)
#2 /home/xxxxxxx/public_html/sites/all/modules/twitter/twitter.module(185): twitter_fetch_timeline('xxxxxxxxxxxxx')
#3 [internal function]: twitter_cron()
#4 /home/xxxxxxx/public_html/includes/module.inc(471): call_user_func_array('twitter_cron', Array)
#5 /home/xxxxxxx/public_html/includes/common.inc(2661): module_invoke_all('cron')
#6 /home/xxxxxxxx/public_html/cron.php(11): drupal_cron_run()
#7 {main}
thrown in /home/xxxxxxx/public_html/sites/all/modules/twitter/twitter.inc on line 477

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

strikehawkecomm’s picture

prbass’s picture

Priority: Critical » Minor
Status: Active » Closed (fixed)

This is an issue with the twitter service rather than the Drupal twitter module as such.

I have been getting this error intermittently for ages, and every so often tried to work out what is causing it but not been able to pin it down. Was it a dodgy XML character, a problem with the parser, or twitter doing something strange? The error was intermittent and I couldn't replicate it.

However, there was a Denial of service attack on Twitter this afternoon which wiped out the whole service. Presto - Three of my cron runs threw up this error whilst the servers were down. Suddenly I could generate this error with every cron run. Now it is working correctly again.

It seems pretty clear then that this is caused by Twitter's server failing rather than any fault in the module. It should be safe to ignore this error in future.

I'm going to mark this as closed to avoid cluttering up the issue queue.

funana’s picture

Got the error right now, one day after the twitter ddos problems...

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /usr/www/users/mysite/sites/all/modules/twitter/twitter.inc:477 Stack trace: #0 /usr/www/users/mysite/sites/all/modules/twitter/twitter.inc(477): SimpleXMLElement->__construct('') #1 /usr/www/users/mysite/sites/all/modules/twitter/twitter.inc(101): _twitter_convert_xml_to_array(NULL) #2 /usr/www/users/mysite/sites/all/modules/twitter/twitter.module(185): twitter_fetch_timeline('namegoeshere') #3 [internal function]: twitter_cron() #4 /usr/www/users/mysite/includes/module.inc(471): call_user_func_array('twitter_cron', Array) #5 /usr/www/users/mysite/includes/common.inc(2661): module_invoke_all('cron') #6 /usr/www/users/mysite/cron.php(11): drupal_cron_run() #7 {main} thrown in /usr/www/users/mysite/sites/all/modules/twitter/twitter.inc on line 477

honigferd’s picture

Same here, but as mentioned before this seems to be a Twitter problem.

Will wait a few hours/days and see.

srhaber’s picture

FileSize
3.62 KB

This has been happening to me too. I "fixed" the problem by wrapping the contents of twitter_cron inside a try/catch clause. Patch attached.

It's basically just:

function twitter_cron() {
  try {
   // contents
  }
  catch (Exception $e) {
    watchdog('twitter', 'Cron failed.');
  }
}

I also recommend setting a high weight value for the twitter module in the system table so it runs last during cron. I set mine to a weight of 20.

Bevan’s picture

Priority: Normal » Minor
FileSize
46.07 KB

srhaber, Patch seems clean and works as expected. Screenshot of watchdog log entry attached.

Prbass, even though the source of the error is twitter.com, the error is frequent, and twitter module can not assume that twitter.com is working. It needs to handle this error better, because other unrelated cron events are not getting executed when twitter is down. srhaber's patch implements the best solution possible, IMHO.

Bevan’s picture

Priority: Minor » Normal
Status: Closed (fixed) » Reviewed & tested by the community
pheraph’s picture

Priority: Minor » Normal

Subscribing, because of same problem here (now testing the try-catch-patch).

stBorchert’s picture

Tested the patch and it works. Connection errors doesn't catch the users eyes anymore.
Would love to see this fixed but there is no stronger status than RTBC.
Maybe "Really reviewed & tested by the community and really ready to be committed" :-)

sinasalek’s picture

Priority: Normal » Critical

same problem here! applied the patch and fixed.
I think this is critical since it prevents cron from running. it should be handled properly.
Marking it critical again.

Thanks

mcurry’s picture

subscribing.

tobiberlin’s picture

Will this patch be included to the next Twitter module version???

Vacilando’s picture

Same problem, waiting for a fixed release.

Anonymous’s picture

I have the same issue here and it is troublesome because it irritates cron. Could the patch be included in the next version?

joetsuihk’s picture

i think #5 patch is too general to solve this.
the correct approach will be in twitter.inc line 101:
from

<?php
$results = _twitter_convert_xml_to_array($results->data);
?>

to

<?php
if (!empty($results->data)) {
  $results = _twitter_convert_xml_to_array($results->data);
}
else {
  return array();
}
?>
greg.harvey’s picture

Version: 6.x-2.6 » 6.x-2.x-dev
Priority: Critical » Normal
Status: Reviewed & tested by the community » Needs work

Well, for me I just ran the Twitter RSS through the W3C validator for feeds and it came back fine. So if the feed is fine, there must be a bug in SimpleXMLElement class in PHP. Either way, at least we can catch the error.

I think the patch in #5 is fine, but for me it should pass more info from the PHP Exception object to watchdog - "Cron failed parsing XML with message: " . $e->message is a bit more informative.

Bevan’s picture

Greg, the issue is not an error in the feed, but when twitter is overloaded and down completely.

greg.harvey’s picture

@Bevan, that's weird, because sometimes I can consistently hit the feed from a browser but Drupal cron consistently fails. I don't see how Twitter would be "down" for cron but "up" for my browser? But we're heading off topic I guess, so I'll shut up. ;-)

Bevan’s picture

Hmm. There must be other issues at play then. Before I applied this patch I noticed that I couldn't get to twitter.com when I was getting these cron errors. Mind you that was a while ago and fast-moving twitter has probably come a long way since then.

islandlinux’s picture

I had this problem while running in a development environment with a firewall that blocked outgoing connections. I suspect the firewall would duplicate the issue when Twitter is down.

Bottom line is that the $data being passed is 'null' and this causes the error message to be displayed.

I patched with the following code, derived from #5, with expanded verbosity:

function twitter_cron() {
  try {
   // contents
  }
  catch (Exception $e) {
    $message = '['.$e->getMessage().'], line '.$e->getLine().' of ['.$e->getFile().']';
    watchdog('twitter', 'cron failed: '.$message, null, WATCHDOG_WARNING);
  }
}
yan’s picture

Status: Needs work » Needs review
FileSize
517 bytes

Same problem here. #15 worked fine for me. Here's a patch against 6.x-2.x-dev.

So which approach is better, #5 or #15?

radj’s picture

+1

steinmb’s picture

Title: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /sites/all/modules/twitter/twitter.inc:477 » Increase readability of errors in watchdog
Version: 6.x-2.x-dev » 6.x-3.x-dev
Status: Needs review » Active

Retagging this issue. The current code catches the error but throw an rather nasty error message to watchdog that is hard for end users to read. This from 'function request()'

throw new TwitterException($error);

Written to watchdog:

    catch (TwitterException $e) {
      watchdog('twitter', '!message', array('!message' => $e->__toString()), WATCHDOG_ERROR);
      drupal_set_message('Twitter returned an error: ' . $e->getMessage(), 'error');
      return FALSE;
    }

Example on a simple network down (I pulled the plug on my local sandbox):

exception 'TwitterException' with message 'php_network_getaddresses: 
getaddrinfo failed: nodename nor servname provided, or not known' in  /drupal/sites/all/modules/twitter/twitter.lib.php:295 
Stack trace: 
#0  /drupal/sites/all/modules/twitter/twitter.lib.php(237): Twitter->request('http://api.twit...', Array, 'GET') 
#1  /drupal/sites/all/modules/twitter/twitter.lib.php(110): Twitter->call('statuses/user_t...', Array, 'GET', '0') 
#2  /drupal/sites/all/modules/twitter/twitter.lib.php(158): Twitter->get_statuses('statuses/user_t...', Array, '0') 
#3  /drupal/sites/all/modules/twitter/twitter.inc(102): Twitter->user_timeline('437502276', Array, '0') 
#4  /drupal/sites/all/modules/twitter/twitter.module(140): twitter_fetch_user_timeline('437502276') 
#5 [internal function]: twitter_cron() #6  /drupal/includes/module.inc(482): call_user_func_array('twitter_cron', Array) 
#7  /drupal/includes/common.inc(2745): module_invoke_all('cron') 

Though a stack trace is useful to a developer, is it a rather scary looking thing to an end user. Perhaps we could make a debug mode/setting, that turn these on when we need better logs from users with problems, but normally we parse and print to watchdog something like:

'Network problem. php_network_getaddresses: 
getaddrinfo failed: nodename nor servname provided, or not known.
juampynr’s picture

Priority: Normal » Major

I have fixed this at 7.x-3.x (see #1383992: Error when adding an account: PDO Exception: Integrity constraint violation in twitter_account_save()). Need to port the last commit at that issue to Drupal 6. Patches are welcome.

dddave’s picture

Version: 6.x-3.x-dev » 6.x-5.x-dev
DamienMcKenna’s picture

Issue summary: View changes
Status: Active » Closed (fixed)

Subsequent commits fixed this: 211ef36 and 71e5664