From c65fb69092d03f5f639084515f4646d3293262fb Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Thu, 31 Aug 2023 07:30:39 +0000 Subject: [PATCH] Handle Lobsters comment parsing TypeErrors Too lazy to debug this: 2023-08-29 12:56:35,111 - root - INFO - Updating lobsters story: yktkwr, index: 55 Traceback (most recent call last): File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run File "/home/tanner/qotnews/apiserver/server.py", line 194, in feed_thread valid = feed.update_story(story) File "/home/tanner/qotnews/apiserver/feed.py", line 74, in update_story res = lobsters.story(story['ref']) File "/home/tanner/qotnews/apiserver/feeds/lobsters.py", line 103, in story s['comments'] = iter_comments(r['comments']) File "/home/tanner/qotnews/apiserver/feeds/lobsters.py", line 76, in iter_comments parent_stack = parent_stack[:indent-1] TypeError: unsupported operand type(s) for -: 'NoneType' and 'int' 2023-08-29T12:56:35Z failed with TypeError --- apiserver/feeds/lobsters.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apiserver/feeds/lobsters.py b/apiserver/feeds/lobsters.py index c333e4a..7214038 100644 --- a/apiserver/feeds/lobsters.py +++ b/apiserver/feeds/lobsters.py @@ -100,7 +100,13 @@ def story(ref): s['title'] = r.get('title', '') s['link'] = SITE_LINK(ref) s['url'] = r.get('url', '') - s['comments'] = iter_comments(r['comments']) + + try: + s['comments'] = iter_comments(r['comments']) + except TypeError: + logging.exception('TypeError iterating lobsters comments, skipping article.') + return False + s['num_comments'] = r['comment_count'] if 'description' in r and r['description']: