Uncaught exception at SimpleXMLElement constructor

coreyp_1 - May 28, 2009 - 22:55
Project:Twitter
Version:6.x-2.6
Component:Code
Category:bug report
Priority:critical
Assigned:marvil07
Status:needs review
Issue tags:exception
Description

I'm using PoorMan's Cron, of course, but that didn't cause the error. This message was thrown:

<br />
<b>Fatal error</b>:  Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /homepages/18/d278310800/htdocs/dev/sites/all/modules/twitter/twitter.inc:448
Stack trace:
#0 /homepages/18/d278310800/htdocs/dev/sites/all/modules/twitter/twitter.inc(448): SimpleXMLElement-&gt;__construct('')
#1 /homepages/18/d278310800/htdocs/dev/sites/all/modules/twitter/twitter.inc(101): _twitter_convert_xml_to_array(NULL)
#2 /homepages/18/d278310800/htdocs/dev/sites/all/modules/twitter/twitter.module(185): twitter_fetch_timeline('jonvibe')
#3 [internal function]: twitter_cron()
#4 /homepages/18/d278310800/htdocs/dev/includes/module.inc(471): call_user_func_array('twitter_cron', Array)
#5 /homepages/18/d278310800/htdocs/dev/sites/all/modules/poormanscron/poormanscron.module(61): module_invoke_all('cron')
#6 [internal function]: poormanscron_exit()
#7 /homepages/18/d278310800/htdocs/dev/includes/module.inc(471): call_user_func_array('poormanscron_ex...', Array)
#8 /homepages/18/d278310800/htdocs/dev/includes/common.inc(1575):  in <b>/homepages/18/d278310800/htdocs/dev/sites/all/modules/twitter/twitter.inc</b> on line <b>448</b><br />

Is there a way that we can catch the error and put it into Watchdog rather than it being able to print to screen?

By the way, the Twitter module has functioned perfectly for two months. I think this is more of a "tying up loose ends" bug.

-Corey

#1

prbass - May 31, 2009 - 11:36

I've recently started having this problem too, although it does still seem to have parsed all of my tweets correctly.

This is a bit of a nightmare to troubleshoot. It could be an issue with Twitter's RSS feed, or with the parser.

I'm looking into it, if I find a way to resolve this I'll post it here.

#2

mackh - July 7, 2009 - 15:02

Also seeing this error.

#3

marvil07 - July 10, 2009 - 12:45
Title:Uncaught Fatal Error» Uncaught exception at SimpleXMLElement constructor
Version:6.x-2.x-dev» 6.x-2.6
Assigned to:Anonymous» marvil07
Status:active» needs review

I had the same error on a recent cron run.

I do not know why we got to that point(I can not reproduce it), but here a patch trying to solve it(testing it changing by by hand $data to null :-p).

AttachmentSize
0001-avoid-exception-on-SimpleXMLElement-constructor.patch 908 bytes

#4

marvil07 - August 4, 2009 - 19:22
Priority:normal» critical

maybe and uncaught exception can be a critical bug. Or maybe 3.x branch is the priority, I really do not know..

#5

prbass - August 6, 2009 - 19:31

See http://drupal.org/node/541892#comment-1896560

This seems to be caused by twitter failing rather than a problem with the twitter module. This would explain why I was not able to reproduce the error before, but could get it on every cron run today whilst there was a DDoS attack shutting down twitter's servers

Perhaps it would be preferable for the module not to spit out this error message when it fails given the fact that twitter is not the most reliable of services. But hey mustn't grumble its not like we are paying them!

#6

plan9 - August 17, 2009 - 12:56

marvil07's patch at #3 solved the problem for me on both 6.x and 5.x installs.
Thanks marvil07 ;)

G

#7

sterndata - August 18, 2009 - 13:13

The patch doesn't work because $data is not necessarily null when the error occurs. The thing is that it seems to be intermittent. My logs show failures for several hours, followed by several hours of success. Therefore, it seems that Twitter is not always sending in the expected information.

#8

plan9 - August 18, 2009 - 13:22

I can also confirm that the patch doesn't work consistently :(

#9

marvil07 - August 22, 2009 - 00:57

The first attempt of this patch was an is_null() verification, but after the report that it does not was not work in all cases I wrotea a patch based on srhaber patch on #541892: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /sites/all/modules/twitter/twitter.inc:477, but applied on the necessary portion of code(the constructor).

We must have clear that Exception are heavy on php, but this seems like a needed case to use.

I also found that all functions that use _twitter_convert_xml_to_array() use it with a foreach, so I'm returning an empty array on /supposed/ twitter fail. Except two of them(twitter_fetch_friends() and twitter_fetch_followers()) that are not used from inside the module AFAIK; so maybe where it's used there is a change to do(but I think it should use it in the same way).

AttachmentSize
0001-Add-try-catch-to-avoid-SimpleXMLelement-exception-on.patch 1.12 KB

#10

mkstalen - September 3, 2009 - 09:08

I applied the patch and the emails I was receiving went away, but I started to get heap and heaps of php errors being logged by drupal (access at http:///admin/reports/dblog) which all looked like this...

Type php
Date Wednesday, September 2, 2009 - 23:00
User Anonymous
Location http:///cron.php
Referrer
Message SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /var/www/html/sites//modules/twitter/twitter.inc on line 478.
Severity error
Hostname
Operations

So I've removed the patch.

#11

plan9 - September 5, 2009 - 17:46

I applied your latest patch marvil07 and although I still get masses of SimpleXMLElement errors in watchdog - punctuated by your patches error message:

'Convering xml to array failed. One possible reason is that twitter is down now. The convert failed with exception !exception.' (spot the typo) cron does at least now successfully complete - which is a great improvement.

Thanks

G

#12

pribeh - September 7, 2009 - 19:19

Applied patch but still get wall of SimpleXMLElement errors. Thanks for your efforts.

#13

TomChiverton - September 8, 2009 - 17:17

Snap. For instance, with 'import Twitter statuses' on, you get a huge stack of errors on users pages:

# warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 10: parser error : Opening and ending tag mismatch: META line 8 and HEAD in /home/drupal/modules/twitter/twitter.inc on line 448.
# warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: in /home/drupal/modules/twitter/twitter.inc on line 448.
# warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: ^ in /home/drupal/modules/twitter/twitter.inc on line 448.
# warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 11: parser error : Opening and ending tag mismatch: P line 11 and BODY in /home/drupal/modules/twitter/twitter.inc on line 448.

etc.

Can anyone say if the 6.3-dev version has this bug too or not ?

#14

cultiv8 - September 9, 2009 - 22:55

I was having the same problems and patch #9 fixed it. Thanks!

#15

criz - September 15, 2009 - 15:36

patch from #9 seems to have fixed it for me too...

#16

nomonstersinme - September 16, 2009 - 13:53

The patch from #9 allows me to run cron successfully now! Thanks!

#17

kratib - October 7, 2009 - 17:58

I used libxml_use_internal_errors(TRUE); just before the $xml = new SimpleXMLElement($data); statement to force the XML library to defer complaining about Twitter error responses. This seems to resolve both the watchdog messages and the cron execution.

 
 

Drupal is a registered trademark of Dries Buytaert.