Skip to content

Commit 70ddd43

Browse files
Merge pull request #58 from Keeper-of-the-Keys/remove-asserts
Replace asserts with Exceptions
2 parents d231ae0 + 1de0ce1 commit 70ddd43

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/gpodder/download.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ class ContentRange(object):
106106
"""
107107

108108
def __init__(self, start, stop, length):
109-
assert start >= 0, "Bad start: %r" % start
110-
assert stop is None or (stop >= 0 and stop >= start), (
111-
"Bad stop: %r" % stop)
109+
if start < 0:
110+
raise Exception("Bad start: %r" % start)
111+
if not all(stop is None or (stop >= 0 and stop >= start)):
112+
raise Exception("Bad stop: %r" % stop)
113+
112114
self.start = start
113115
self.stop = stop
114116
self.length = length
@@ -563,7 +565,9 @@ def removed_from_list(self):
563565
util.delete_file(self.tempname)
564566

565567
def __init__(self, episode):
566-
assert episode.download_task is None
568+
if episode.download_task is not None:
569+
raise Exception('Download already in progress.')
570+
567571
self.__status = DownloadTask.INIT
568572
self.__status_changed = True
569573
self.__episode = episode

src/gpodder/model.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
class NoHandlerForURL(Exception):
5050
pass
5151

52+
class DuplicatePodcastException(Exception):
53+
pass
5254

5355
def fetch_channel(channel, config):
5456
max_episodes = config.limit.episodes
@@ -807,7 +809,9 @@ def save(self):
807809
self.model._append_podcast(self)
808810

809811
def get_statistics(self):
810-
assert self.id
812+
# The following was an assert, it is not clear to me how this can ever happen.
813+
if not self.id:
814+
raise Exception('get_statistics() - No podcast ID defined.')
811815

812816
total = len(self.episodes)
813817

@@ -983,7 +987,9 @@ def get_podcasts(self):
983987
return self.podcasts
984988

985989
def load_podcast(self, url, create=True, authentication_tokens=None):
986-
assert all(url != podcast.url for podcast in self.get_podcasts())
990+
if not all(url != podcast.url for podcast in self.get_podcasts()):
991+
raise DuplicatePodcastException
992+
987993
return self.PodcastClass.load_(self, url, create, authentication_tokens)
988994

989995
def get_prefixes(self):

src/gpodder/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ def sanitize_filename(filename, max_length=0, use_ascii=False):
715715
If use_ascii is True, don't encode in the native language,
716716
but use only characters from the ASCII character set.
717717
"""
718-
assert isinstance(filename, str)
718+
if not isinstance(filename, str):
719+
rasie Exception('filename is not a string')
719720

720721
if max_length > 0 and len(filename) > max_length:
721722
logger.info('Limiting file/folder name "%s" to %d characters.', filename, max_length)

0 commit comments

Comments
 (0)