Skip to content

Fix: Crashes on praw.exceptions #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions bdfr/archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Union

import dict2xml
import praw.exceptions
import praw.models
import prawcore
import yaml
Expand Down Expand Up @@ -46,22 +47,25 @@ def download(self):
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)

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]:
Expand Down
5 changes: 3 additions & 2 deletions bdfr/cloner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collections.abc import Iterable
from time import sleep

import praw.exceptions
import prawcore

from bdfr.archiver import Archiver
Expand All @@ -24,9 +25,9 @@ def download(self):
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)
4 changes: 2 additions & 2 deletions bdfr/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def get_subreddits(self) -> list[praw.models.ListingGenerator]:
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

Expand Down Expand Up @@ -382,7 +382,7 @@ def get_user_data(self) -> list[Iterator]:
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)
Expand Down
4 changes: 2 additions & 2 deletions bdfr/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def download(self):
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)
Expand Down