Handle all-zeros KeyError for removed torrents alerts

This commit is contained in:
Calum Lind 2014-01-18 14:11:44 +00:00
parent 01d2ef84ba
commit d12f0365d5
1 changed files with 10 additions and 10 deletions

View File

@ -947,7 +947,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_torrent_checked") log.debug("on_alert_torrent_checked")
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
# Check to see if we're forcing a recheck and set it back to paused # Check to see if we're forcing a recheck and set it back to paused
@ -966,7 +966,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_tracker_reply: %s", decode_string(alert.message())) log.debug("on_alert_tracker_reply: %s", decode_string(alert.message()))
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
# Set the tracker status for the torrent # Set the tracker status for the torrent
@ -984,7 +984,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_tracker_announce") log.debug("on_alert_tracker_announce")
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
# Set the tracker status for the torrent # Set the tracker status for the torrent
@ -995,7 +995,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_tracker_warning") log.debug("on_alert_tracker_warning")
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
tracker_status = 'Warning: %s' % decode_string(alert.message()) tracker_status = 'Warning: %s' % decode_string(alert.message())
# Set the tracker status for the torrent # Set the tracker status for the torrent
@ -1006,7 +1006,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_tracker_error") log.debug("on_alert_tracker_error")
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
tracker_status = "Error: %s" % decode_string(alert.msg) tracker_status = "Error: %s" % decode_string(alert.msg)
torrent.set_tracker_status(tracker_status) torrent.set_tracker_status(tracker_status)
@ -1016,7 +1016,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_storage_moved") log.debug("on_alert_storage_moved")
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
torrent.set_save_path(os.path.normpath(alert.handle.save_path())) torrent.set_save_path(os.path.normpath(alert.handle.save_path()))
torrent.set_move_completed(False) torrent.set_move_completed(False)
@ -1114,7 +1114,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_metadata_received") log.debug("on_alert_metadata_received")
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
torrent.on_metadata_received() torrent.on_metadata_received()
@ -1123,7 +1123,7 @@ class TorrentManager(component.Component):
log.debug("on_alert_file_error: %s", decode_string(alert.message())) log.debug("on_alert_file_error: %s", decode_string(alert.message()))
try: try:
torrent = self.torrents[str(alert.handle.info_hash())] torrent = self.torrents[str(alert.handle.info_hash())]
except RuntimeError: except (RuntimeError, KeyError):
return return
torrent.update_state() torrent.update_state()
@ -1136,8 +1136,8 @@ class TorrentManager(component.Component):
torrent_id = str(alert.handle.info_hash()) torrent_id = str(alert.handle.info_hash())
except RuntimeError: except RuntimeError:
return return
component.get("EventManager").emit( if torrent_id in self.torrents:
TorrentFileCompletedEvent(torrent_id, alert.index)) component.get("EventManager").emit(TorrentFileCompletedEvent(torrent_id, alert.index))
def on_alert_state_update(self, alert): def on_alert_state_update(self, alert):
"""Alert handler for libtorrent state_update_alert """Alert handler for libtorrent state_update_alert