mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-26 04:32:51 +01:00
RSS: Log feed URL when feedparser.parse raises exceptions
This commit is contained in:
parent
4db32e24a5
commit
fccb4f705b
@ -356,8 +356,17 @@ class RSS(callbacks.Plugin):
|
|||||||
handlers.append(ProxyHandler(
|
handlers.append(ProxyHandler(
|
||||||
{'https': utils.force(utils.web.proxy())}))
|
{'https': utils.force(utils.web.proxy())}))
|
||||||
with feed.lock:
|
with feed.lock:
|
||||||
d = feedparser.parse(feed.url, etag=feed.etag,
|
try:
|
||||||
modified=feed.modified, handlers=handlers)
|
d = feedparser.parse(feed.url, etag=feed.etag,
|
||||||
|
modified=feed.modified, handlers=handlers)
|
||||||
|
except socket.error as e:
|
||||||
|
self.log.warning("Network error while fetching <%s>: %s",
|
||||||
|
feed.url, e)
|
||||||
|
feed.last_exception = e
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
self.log.error("Failed to fetch <%s>: %s", feed.url, e)
|
||||||
|
raise # reraise so @log.firewall prints the traceback
|
||||||
if 'status' not in d or d.status != 304: # Not modified
|
if 'status' not in d or d.status != 304: # Not modified
|
||||||
if 'etag' in d:
|
if 'etag' in d:
|
||||||
feed.etag = d.etag
|
feed.etag = d.etag
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
import functools
|
import functools
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
import socket
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import feedparser
|
import feedparser
|
||||||
@ -362,7 +363,22 @@ class RSSTestCase(ChannelPluginTestCase):
|
|||||||
timeFastForward(1.1)
|
timeFastForward(1.1)
|
||||||
mock._data = not_well_formed
|
mock._data = not_well_formed
|
||||||
self.assertRegexp('rss http://example.com/',
|
self.assertRegexp('rss http://example.com/',
|
||||||
'Parser error')
|
'Parser error: .*mismatch')
|
||||||
|
|
||||||
|
def testSocketError(self):
|
||||||
|
class MockResponse:
|
||||||
|
headers = {}
|
||||||
|
url = ''
|
||||||
|
def read(self):
|
||||||
|
raise socket.error("oh no")
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
mock = MockResponse()
|
||||||
|
with patch("urllib.request.OpenerDirector.open", return_value=mock):
|
||||||
|
timeFastForward(1.1)
|
||||||
|
self.assertRegexp('rss http://example.com/',
|
||||||
|
'Parser error: .*oh no')
|
||||||
|
|
||||||
if network:
|
if network:
|
||||||
timeout = 5 # Note this applies also to the above tests
|
timeout = 5 # Note this applies also to the above tests
|
||||||
|
Loading…
Reference in New Issue
Block a user