Skip to content

Commit

Permalink
Merge pull request #4921 from rtibbles/prevent_pop_error
Browse files Browse the repository at this point in the history
Catch pops from an empty list.
  • Loading branch information
aronasorman committed Feb 26, 2016
2 parents a804fb7 + db0f4f8 commit e32f47e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions kalite/updates/download_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ def load(self):

def remove_file(self, youtube_id):
"""Remove the last file from the list, and check that it matches the passed in youtube_id"""
removed_file = self.queue.pop()
if removed_file.get("youtube_id") != youtube_id:
logging.warn("Tried to remove {youtube_id} from file queue but found {removed_file} instead.".format(youtube_id=youtube_id, removed_file=removed_file.get("youtube_id")))
else:
self.save()
try:
removed_file = self.queue.pop()
if removed_file.get("youtube_id") != youtube_id:
logging.warn("Tried to remove {youtube_id} from file queue but found {removed_file} instead.".format(youtube_id=youtube_id, removed_file=removed_file.get("youtube_id")))
else:
self.save()
except IndexError:
logging.warn("Tried to remove {youtube_id} from file queue, but was empty instead.".format(youtube_id=youtube_id))

def clear(self):
"""Clear all currently queued videos"""
Expand Down

0 comments on commit e32f47e

Please sign in to comment.