RSS: Log feed URL when feedparser.parse raises exceptions

This commit is contained in:
Valentin Lorentz 2022-08-07 18:50:14 +02:00
parent 4db32e24a5
commit fccb4f705b
2 changed files with 28 additions and 3 deletions

View File

@ -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

View File

@ -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