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
Comments
Comment #1
prbass commentedI'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.
Comment #2
mackh commentedAlso seeing this error.
Comment #3
marvil07 commentedI 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).
Comment #4
marvil07 commentedmaybe and uncaught exception can be a critical bug. Or maybe 3.x branch is the priority, I really do not know..
Comment #5
prbass commentedSee 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!
Comment #6
plan9 commentedmarvil07's patch at #3 solved the problem for me on both 6.x and 5.x installs.
Thanks marvil07 ;)
G
Comment #7
sterndata commentedThe 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.
Comment #8
plan9 commentedI can also confirm that the patch doesn't work consistently :(
Comment #9
marvil07 commentedThe 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: Increase readability of errors in watchdog, 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).Comment #10
mkstalen commentedI 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.
Comment #11
plan9 commentedI 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
Comment #12
pribeh commentedApplied patch but still get wall of SimpleXMLElement errors. Thanks for your efforts.
Comment #13
TomChiverton commentedSnap. 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 ?
Comment #14
rj commentedI was having the same problems and patch #9 fixed it. Thanks!
Comment #15
crizpatch from #9 seems to have fixed it for me too...
Comment #16
nomonstersinme commentedThe patch from #9 allows me to run cron successfully now! Thanks!
Comment #17
infojunkieI 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.Comment #18
Anonymous (not verified) commentedRE: #17: is that in addition to, or in lieu of the patch from #9?
Comment #19
infojunkieAFAIR, I didn't use the patch.
Comment #20
marvil07 commentedComment #21
juampynr commentedApplied patch from marvil07 with some little rewording and added t(). I have verified it forcing an Exception within the "try" block.
http://drupalcode.org/project/twitter.git/commitdiff/fb7418f4c1d219078b5...
As there were some other commits in the dev branch of 6.x-2.x that are not present at 6.x-2.6, I have released a new version at http://drupal.org/node/1319030, although I suggest to upgrade to the latest version at the project page (http://drupal.org/project/twitter).
Cheers