From dfd8c8b40643d5e6508d38a47d284abcc0223303 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 9 Jan 2013 10:27:22 -0500 Subject: [PATCH] feed: Raise the new InvalidFeedConfig on missing feed.url You can't fetch a feed without a URL. This new error message makes the cause explicit, compared to the somewhat ambigious former error messages: fetch $NAME (None -> $TO) process $NAME (None -> $TO) HTTP status 200 could not get HTTP headers: $NAME (None -> $TO) unrecognized version: $NAME (None -> $TO) sax parsing error: :2:0: no element found: $NAME (None -> $TO) I was getting URL-less feeds when I clobbered my ~/.config/rss2email/config [1], removing some newer entries. However, because I never deleted the feeds explicitly, they were repopulated (without their URL) from ~/.config/rss2email/feeds.dat, and subsequent runs generated the above error. [1]: The clobbering was related to my dotfile management, and not due to an rss2email issue. Signed-off-by: W. Trevor King --- rss2email/error.py | 22 +++++++++++++++++----- rss2email/feed.py | 10 ++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/rss2email/error.py b/rss2email/error.py index d4c990e..7223d36 100644 --- a/rss2email/error.py +++ b/rss2email/error.py @@ -112,10 +112,21 @@ class FeedError (RSS2EmailError): self.feed = feed -class InvalidFeedName (FeedError): +class InvalidFeedConfig (FeedError): + def __init__(self, setting, feed, message=None, **kwargs): + if not message: + message = "invalid feed configuration {}".format( + {setting: getattr(feed, setting)}) + super(InvalidFeedConfig, self).__init__( + feed=feed, message=message, **kwargs) + self.setting = setting + + +class InvalidFeedName (InvalidFeedConfig): def __init__(self, name, **kwargs): message = "invalid feed name '{}'".format(name) - super(InvalidFeedName, self).__init__(message=message, **kwargs) + super(InvalidFeedName, self).__init__( + setting='name', message=message, **kwargs) class ProcessingError (FeedError): @@ -183,10 +194,11 @@ class NoDataFile (DataFileError): "'r2e new' first.") -class NoToEmailAddress (FeedsError, FeedError): - def __init__(self, **kwargs): +class NoToEmailAddress (InvalidFeedConfig, FeedsError): + def __init__(self, feed, **kwargs): message = 'no target email address has been defined' - super(NoToEmailAddress, self).__init__(message=message, **kwargs) + super(NoToEmailAddress, self).__init__( + setting='to', feed=feed, message=message, **kwargs) def log(self): super(NoToEmailAddress, self).log() diff --git a/rss2email/feed.py b/rss2email/feed.py index 3c6513d..ccb502a 100644 --- a/rss2email/feed.py +++ b/rss2email/feed.py @@ -106,6 +106,14 @@ class Feed (object): ... rss2email.error.InvalidFeedName: invalid feed name 'invalid name' + You must define a URL: + + >>> Feed(name='feed-without-a-url', to='a@b.com').run(send=False) + Traceback (most recent call last): + ... + rss2email.error.InvalidFeedConfig: invalid feed configuration {'url': None} + + Cleanup `CONFIG`. >>> CONFIG['DEFAULT']['to'] = '' @@ -285,6 +293,8 @@ class Feed (object): 200 """ _LOG.info('fetch {}'.format(self)) + if not self.url: + raise _error.InvalidFeedConfig(setting='url', feed=self) if self.section in self.config: config = self.config[self.section] else: -- 2.26.2