Handle KeyErrors when event data is not present.

The bot previously assumed that all event stream JSON blobs would always
have the data that the bot is interested in. Handle KeyError exceptions
when that data is missing.

Change-Id: I6ad034c5197c6778c39c334e3d9246c3b1356a81
This commit is contained in:
Clark Boylan 2012-08-24 13:28:46 -07:00
parent 383860d352
commit 92b7468921
1 changed files with 11 additions and 6 deletions

View File

@ -193,12 +193,17 @@ class Gerrit(threading.Thread):
self.ircbot.send(channel, msg)
def _read(self, data):
channel_set = (self.channel_config.projects.get(
data['change']['project'], set()) &
self.channel_config.events.get(
data['type'], set()) &
self.channel_config.branches.get(
data['change']['branch'], set()))
try:
channel_set = (self.channel_config.projects.get(
data['change']['project'], set()) &
self.channel_config.events.get(
data['type'], set()) &
self.channel_config.branches.get(
data['change']['branch'], set()))
except KeyError:
# The data we care about was not present, no channels want
# this event.
channel_set = set()
self.log.info('Potential channels to receive event notification: %s' %
channel_set)
for channel in channel_set: