Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Better error messages from get_create_event_for_room (#11638)
Browse files Browse the repository at this point in the history
"Unknown room" can mean a multitude of things here. To help with debugging, add
some more words to the exception text.
  • Loading branch information
richvdh authored Jan 4, 2022
1 parent 8422a7f commit bd9821f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/11638.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve the error messages from `get_create_event_for_room`.
6 changes: 5 additions & 1 deletion synapse/storage/databases/main/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,15 @@ async def get_create_event_for_room(self, room_id: str) -> EventBase:
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)
Expand Down

0 comments on commit bd9821f

Please sign in to comment.