Uncaught exception at SimpleXMLElement constructor
coreyp_1 - May 28, 2009 - 22:55
| Project: | |
| 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->__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
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
Also seeing this error.
#3
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).
#4
maybe and uncaught exception can be a critical bug. Or maybe 3.x branch is the priority, I really do not know..
#5
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
marvil07's patch at #3 solved the problem for me on both 6.x and 5.x installs.
Thanks marvil07 ;)
G
#7
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
I can also confirm that the patch doesn't work consistently :(
#9
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()andtwitter_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).#10
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
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
Applied patch but still get wall of SimpleXMLElement errors. Thanks for your efforts.
#13
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
I was having the same problems and patch #9 fixed it. Thanks!
#15
patch from #9 seems to have fixed it for me too...
#16
The patch from #9 allows me to run cron successfully now! Thanks!
#17
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.