Better error messages from get_create_event_for_room (#11638)

"Unknown room" can mean a multitude of things here. To help with debugging, add
some more words to the exception text.
This commit is contained in:
Richard van der Hoff 2022-01-04 16:10:05 +00:00 committed by GitHub
parent 8422a7f7f6
commit bd9821f7f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

1
changelog.d/11638.misc Normal file
View file

@ -0,0 +1 @@
Improve the error messages from `get_create_event_for_room`.

View file

@ -177,11 +177,15 @@ class StateGroupWorkerStore(EventsWorkerStore, SQLBaseStore):
NotFoundError if the room is unknown
"""
state_ids = await self.get_current_state_ids(room_id)
if not state_ids:
raise NotFoundError(f"Current state for room {room_id} is empty")
create_id = state_ids.get((EventTypes.Create, ""))
# If we can't find the create event, assume we've hit a dead end
if not create_id:
raise NotFoundError("Unknown room %s" % (room_id,))
raise NotFoundError(f"No create event in current state for room {room_id}")
# Retrieve the room's create event and return
create_event = await self.get_event(create_id)