Adding subreddit name to a few error messages.

This commit is contained in:
Michael Lazar
2016-10-17 17:43:10 -07:00
parent de9edd1ce0
commit 9675fb4ba4
4 changed files with 15 additions and 5 deletions

View File

@@ -429,7 +429,10 @@ class SubredditContent(Content):
try: try:
self.get(0) self.get(0)
except IndexError: except IndexError:
raise exceptions.SubredditError('No submissions') full_name = self.name
if self.order:
full_name += '/' + self.order
raise exceptions.NoSubmissionsError(full_name)
@classmethod @classmethod
def from_name(cls, reddit, name, loader, order=None, query=None): def from_name(cls, reddit, name, loader, order=None, query=None):

View File

@@ -22,8 +22,13 @@ class SubmissionError(RTVError):
"Submission could not be loaded" "Submission could not be loaded"
class SubredditError(RTVError): class NoSubmissionsError(RTVError):
"Subreddit could not be reached" "No submissions for the given page"
def __init__(self, name):
self.name = name
message = '`{0}` has no submissions'.format(name)
super(NoSubmissionsError, self).__init__(message)
class SubscriptionError(RTVError): class SubscriptionError(RTVError):

View File

@@ -120,6 +120,7 @@ class LoadScreen(object):
(praw.errors.OAuthScopeRequired, 'Not logged in'), (praw.errors.OAuthScopeRequired, 'Not logged in'),
(praw.errors.LoginRequired, 'Not logged in'), (praw.errors.LoginRequired, 'Not logged in'),
(praw.errors.InvalidCaptcha, 'Error, captcha required'), (praw.errors.InvalidCaptcha, 'Error, captcha required'),
(praw.errors.InvalidSubreddit, '{0.args[0]}'),
(praw.errors.PRAWException, '{0.__class__.__name__}'), (praw.errors.PRAWException, '{0.__class__.__name__}'),
(requests.exceptions.RequestException, '{0.__class__.__name__}'), (requests.exceptions.RequestException, '{0.__class__.__name__}'),
] ]

View File

@@ -399,8 +399,9 @@ def test_content_subreddit_me(reddit, oauth, refresh_token, terminal):
# If there is no submitted content, an error should be raised # If there is no submitted content, an error should be raised
if terminal.loader.exception: if terminal.loader.exception:
assert isinstance(terminal.loader.exception, exceptions.SubredditError) assert isinstance(terminal.loader.exception,
exceptions.NoSubmissionsError)
assert terminal.loader.exception.name == '/u/me'
def test_content_subscription(reddit, terminal): def test_content_subscription(reddit, terminal):