1 # Copyright (C) 2012 W. Trevor King <wking@tremily.us>
3 # This file is part of rss2email.
5 # rss2email is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 2 of the License, or (at your option) version 3 of
10 # rss2email is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # rss2email. If not, see <http://www.gnu.org/licenses/>.
17 """rss2email-specific errors
20 from . import LOG as _LOG
22 import pprint as _pprint
24 import feedparser as _feedparser
25 import html2text as _html2text
28 class RSS2EmailError (Exception):
29 def __init__(self, message):
30 super(RSS2EmailError, self).__init__(message)
34 if self.__cause__ is not None:
35 _LOG.error('cause: {}'.format(self.__cause__))
38 class TimeoutError (RSS2EmailError):
39 def __init__(self, time_limited_function, message=None):
41 if time_limited_function.error is not None:
43 'error while running time limited function: {}'.format(
44 time_limited_function.error[1]))
46 message = '{} second timeout exceeded'.format(
47 time_limited_function.timeout)
48 super(TimeoutError, self).__init__(message=message)
49 self.time_limited_function = time_limited_function
52 class NoValidEncodingError (RSS2EmailError, ValueError):
53 def __init__(self, string, encodings):
54 message = 'no valid encoding for {} in {}'.format(string, encodings)
55 super(NoValidEncodingError, self).__init__(message=message)
57 self.encodings = encodings
60 class SMTPConnectionError (ValueError, RSS2EmailError):
61 def __init__(self, server, message=None):
63 message = 'could not connect to mail server {}'.format(server)
64 super(SMTPConnectionError, self).__init__(message=message)
68 super(SMTPConnectionError, self).log()
70 'check your config file to confirm that smtp-server and other '
71 'mail server settings are configured properly')
72 if hasattr(self.__cause__, 'reason'):
73 _LOG.error('reason: {}'.format(self.__cause__.reason))
76 class SMTPAuthenticationError (SMTPConnectionError):
77 def __init__(self, server, username):
79 'could not authenticate with mail server {} as user {}'.format(
81 super(SMTPConnectionError, self).__init__(
82 server=server, message=message)
84 self.username = username
87 class SendmailError (RSS2EmailError):
88 def __init__(self, status=None, stdout=None, stderr=None):
90 message = 'sendmail exited with code {}'.format(status)
93 super(SendmailError, self).__init__(message=message)
99 super(SendmailError, self).log()
101 'Error attempting to send email via sendmail. You may need '
102 'to configure rss2email to use an SMTP server. Please refer '
103 'to the rss2email documentation or website ({}) for complete '
104 'documentation.').format(__url__))
107 class FeedError (RSS2EmailError):
108 def __init__(self, feed, message=None):
110 message = 'error with feed {}'.format(feed.name)
111 super(FeedError, self).__init__(message=message)
115 class InvalidFeedName (FeedError):
116 def __init__(self, name, **kwargs):
117 message = "invalid feed name '{}'".format(name)
118 super(InvalidFeedName, self).__init__(message=message, **kwargs)
121 class ProcessingError (FeedError):
122 def __init__(self, parsed, feed, **kwargs):
124 message = 'error processing feed {}'.format(feed)
125 super(FeedError, self).__init__(feed=feed, message=message)
129 super(ProcessingError, self).log()
130 if type(self) == ProcessingError: # not a more specific subclass
132 '=== rss2email encountered a problem with this feed ===')
134 '=== See the rss2email FAQ at {} for assistance ==='.format(
137 '=== If this occurs repeatedly, send this to {} ==='.format(
140 'error: {} {}'.format(
141 self.parsed.get('bozo_exception', "can't process"),
143 _LOG.warning(_pprint.pformat(self.parsed))
144 _LOG.warning('rss2email', __version__)
145 _LOG.warning('feedparser', _feedparser.__version__)
146 _LOG.warning('html2text', _html2text.__version__)
147 _LOG.warning('Python', _sys.version)
148 _LOG.warning('=== END HERE ===')
151 class HTTPError (ProcessingError):
152 def __init__(self, status, feed, **kwargs):
153 message = 'HTTP status {} fetching feed {}'.format(status, feed)
154 super(FeedError, self).__init__(feed=feed, message=message)
158 class FeedsError (RSS2EmailError):
159 def __init__(self, feeds=None, message=None, **kwargs):
161 message = 'error with feeds'
162 super(FeedsError, self).__init__(message=message, **kwargs)
166 class DataFileError (FeedsError):
167 def __init__(self, feeds, message=None):
169 message = 'problem with the feed data file {}'.format(
171 super(DataFileError, self).__init__(feeds=feeds, message=message)
174 class NoDataFile (DataFileError):
175 def __init__(self, feeds):
176 message = 'feed data file {} does not exist'.format(feeds.datafile)
177 super(NoDataFile, self).__init__(feeds=feeds, message=message)
180 super(NoDataFile, self).log()
182 "if you're using r2e for the first time, you have to run "
186 class NoToEmailAddress (FeedsError, FeedError):
187 def __init__(self, **kwargs):
188 message = 'no target email address has been defined'
189 super(NoToEmailAddress, self).__init__(message=message, **kwargs)
192 super(NoToEmailAddress, self).log()
194 "please run 'r2e email emailaddress' or "
195 "'r2e add name url emailaddress'.")
198 class OPMLReadError (RSS2EmailError):
199 def __init__(self, **kwargs):
200 message = 'error reading OPML'
201 super(RSS2EmailError, self).__init__(message=message, **kwargs)