mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 12:12:54 +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(
|
||||
{'https': utils.force(utils.web.proxy())}))
|
||||
with feed.lock:
|
||||
d = feedparser.parse(feed.url, etag=feed.etag,
|
||||
modified=feed.modified, handlers=handlers)
|
||||
try:
|
||||
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 'etag' in d:
|
||||
feed.etag = d.etag
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
import functools
|
||||
from unittest.mock import patch
|
||||
import socket
|
||||
import sys
|
||||
|
||||
import feedparser
|
||||
@ -362,7 +363,22 @@ class RSSTestCase(ChannelPluginTestCase):
|
||||
timeFastForward(1.1)
|
||||
mock._data = not_well_formed
|
||||
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:
|
||||
timeout = 5 # Note this applies also to the above tests
|
||||
|
Loading…
Reference in New Issue
Block a user