1
0
Fork 0
mirror of synced 2024-09-29 16:51:30 +13:00

Fix: Crashes on praw.exceptions

This commit is contained in:
Thomas 2023-02-18 23:51:15 +01:00
parent 5cf2c81b0c
commit e0e5db85e3
No known key found for this signature in database
GPG key ID: 0CFD61744DA1A21C
4 changed files with 19 additions and 14 deletions

View file

@ -9,6 +9,7 @@ from time import sleep
from typing import Union
import dict2xml
import praw.exceptions
import praw.models
import prawcore
import yaml
@ -46,9 +47,9 @@ class Archiver(RedditConnector):
continue
logger.debug(f"Attempting to archive submission {submission.id}")
self.write_entry(submission)
except prawcore.PrawcoreException as e:
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"Submission {submission.id} failed to be archived due to a PRAW exception: {e}")
except prawcore.PrawcoreException as e:
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"The submission after {submission.id} failed to download due to a PRAW exception: {e}")
logger.debug("Waiting 60 seconds to continue")
sleep(60)
@ -56,12 +57,15 @@ class Archiver(RedditConnector):
def get_submissions_from_link(self) -> list[list[praw.models.Submission]]:
supplied_submissions = []
for sub_id in self.args.link:
if len(sub_id) == 6:
supplied_submissions.append(self.reddit_instance.submission(id=sub_id))
elif re.match(r"^\w{7}$", sub_id):
supplied_submissions.append(self.reddit_instance.comment(id=sub_id))
else:
supplied_submissions.append(self.reddit_instance.submission(url=sub_id))
try:
if len(sub_id) == 6:
supplied_submissions.append(self.reddit_instance.submission(id=sub_id))
elif re.match(r"^\w{7}$", sub_id):
supplied_submissions.append(self.reddit_instance.comment(id=sub_id))
else:
supplied_submissions.append(self.reddit_instance.submission(url=sub_id))
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"Error getting submission {sub_id} from link: {e}")
return [supplied_submissions]
def get_user_data(self) -> list[Iterator]:

View file

@ -5,6 +5,7 @@ from collections.abc import Iterable
from time import sleep
import prawcore
import praw.exceptions
from bdfr.archiver import Archiver
from bdfr.configuration import Configuration
@ -24,9 +25,9 @@ class RedditCloner(RedditDownloader, Archiver):
try:
self._download_submission(submission)
self.write_entry(submission)
except prawcore.PrawcoreException as e:
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"Submission {submission.id} failed to be cloned due to a PRAW exception: {e}")
except prawcore.PrawcoreException as e:
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"The submission after {submission.id} failed to download due to a PRAW exception: {e}")
logger.debug("Waiting 60 seconds to continue")
sleep(60)

View file

@ -290,7 +290,7 @@ class RedditConnector(metaclass=ABCMeta):
else:
out.append(self.create_filtered_listing_generator(reddit))
logger.debug(f"Added submissions from subreddit {reddit}")
except (errors.BulkDownloaderException, praw.exceptions.PRAWException) as e:
except (errors.BulkDownloaderException, prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"Failed to get submissions for subreddit {reddit}: {e}")
return out
@ -382,7 +382,7 @@ class RedditConnector(metaclass=ABCMeta):
if self.args.saved:
logger.debug(f"Retrieving saved posts of user {user}")
generators.append(self.reddit_instance.redditor(user).saved(limit=self.args.limit))
except prawcore.PrawcoreException as e:
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"User {user} failed to be retrieved due to a PRAW exception: {e}")
logger.debug("Waiting 60 seconds to continue")
sleep(60)

View file

@ -47,9 +47,9 @@ class RedditDownloader(RedditConnector):
for submission in generator:
try:
self._download_submission(submission)
except prawcore.PrawcoreException as e:
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"Submission {submission.id} failed to download due to a PRAW exception: {e}")
except prawcore.PrawcoreException as e:
except (prawcore.PrawcoreException, praw.exceptions.PRAWException) as e:
logger.error(f"The submission after {submission.id} failed to download due to a PRAW exception: {e}")
logger.debug("Waiting 60 seconds to continue")
sleep(60)