mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-01-19 04:30:10 +00:00
Return error instead of panic when first event is not m.room.create
This commit is contained in:
parent
520806d413
commit
5a7bb1e8f1
@ -696,18 +696,27 @@ impl Service {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// If there was no create event yet, assume we are creating a room
|
// If there was no create event yet, assume we are creating a room
|
||||||
let room_version_id = self.get_room_version(room_id)?.unwrap_or_else(|| {
|
let room_version_id = self
|
||||||
if event_type != TimelineEventType::RoomCreate {
|
.get_room_version(room_id)?
|
||||||
panic!("non-create event for room of unknown version");
|
.or_else(|| {
|
||||||
}
|
if event_type == TimelineEventType::RoomCreate {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct RoomCreate {
|
struct RoomCreate {
|
||||||
room_version: RoomVersionId,
|
room_version: RoomVersionId,
|
||||||
}
|
}
|
||||||
let content = serde_json::from_str::<RoomCreate>(content.get())
|
let content = serde_json::from_str::<RoomCreate>(content.get())
|
||||||
.expect("Invalid content in RoomCreate pdu.");
|
.expect("Invalid content in RoomCreate pdu.");
|
||||||
content.room_version
|
Some(content.room_version)
|
||||||
});
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ok_or_else(|| {
|
||||||
|
Error::InconsistentRoomState(
|
||||||
|
"non-create event for room of unknown version",
|
||||||
|
room_id.to_owned(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||||
|
|
||||||
|
@ -82,6 +82,8 @@ pub enum Error {
|
|||||||
PathError(#[from] axum::extract::rejection::PathRejection),
|
PathError(#[from] axum::extract::rejection::PathRejection),
|
||||||
#[error("from {0}: {1}")]
|
#[error("from {0}: {1}")]
|
||||||
RedactionError(OwnedServerName, ruma::canonical_json::RedactionError),
|
RedactionError(OwnedServerName, ruma::canonical_json::RedactionError),
|
||||||
|
#[error("{0} in {1}")]
|
||||||
|
InconsistentRoomState(&'static str, ruma::OwnedRoomId),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
|
Loading…
Reference in New Issue
Block a user