Catch exceptions for room events and print out a error message.

This commit is contained in:
poljar (Damir Jelić) 2018-02-25 18:53:11 +01:00
parent 31fc14c27f
commit d97323e7e8

View file

@ -139,21 +139,31 @@ class RoomInfo():
membership_events = []
other_events = []
for event in parsed_dict:
if event["type"] == "m.room.message":
other_events.append(RoomInfo._message_from_event(event))
elif event["type"] == "m.room.member":
membership_events.append(RoomInfo._membership_from_dict(event))
elif event["type"] == "m.room.power_levels":
other_events.append(RoomPowerLevels.from_dict(event))
elif event["type"] == "m.room.topic":
other_events.append(RoomTopicEvent.from_dict(event))
elif event["type"] == "m.room.redaction":
other_events.append(RoomRedactionEvent.from_dict(event))
elif event["type"] == "m.room.name":
other_events.append(RoomNameEvent.from_dict(event))
elif event["type"] == "m.room.aliases":
other_events.append(RoomAliasEvent.from_dict(event))
try:
for event in parsed_dict:
if event["type"] == "m.room.message":
other_events.append(RoomInfo._message_from_event(event))
elif event["type"] == "m.room.member":
membership_events.append(
RoomInfo._membership_from_dict(event))
elif event["type"] == "m.room.power_levels":
other_events.append(RoomPowerLevels.from_dict(event))
elif event["type"] == "m.room.topic":
other_events.append(RoomTopicEvent.from_dict(event))
elif event["type"] == "m.room.redaction":
other_events.append(RoomRedactionEvent.from_dict(event))
elif event["type"] == "m.room.name":
other_events.append(RoomNameEvent.from_dict(event))
elif event["type"] == "m.room.aliases":
other_events.append(RoomAliasEvent.from_dict(event))
except (ValueError, TypeError, KeyError) as error:
message = ("{prefix}matrix: Error parsing "
"room event of type {type}: {error}").format(
prefix=W.prefix("error"),
type=event["type"],
error=str(error))
W.prnt("", message)
raise
return (membership_events, other_events)