Replace panic!() with unreachable!()

This commit is contained in:
Matthias Ahouansou 2024-04-11 17:19:42 +00:00 committed by Val Lorentz
parent 8175bc1246
commit e88d137bd7
2 changed files with 5 additions and 13 deletions

View file

@ -147,7 +147,7 @@ pub async fn create_room_route(
);
}
RoomVersionId::V11 => {} // V11 removed the "creator" key
_ => panic!("Unexpected room version {}", room_version),
_ => unreachable!("Validity of room version already checked"),
}
content.insert(
@ -172,7 +172,7 @@ pub async fn create_room_route(
| RoomVersionId::V9
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(sender_user.clone()),
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
_ => panic!("Unexpected room version {}", room_version),
_ => unreachable!("Validity of room version already checked"),
};
let mut content = serde_json::from_str::<CanonicalJsonObject>(
to_raw_value(&content)
@ -633,7 +633,7 @@ pub async fn upgrade_room_route(
// "creator" key no longer exists in V11 rooms
create_event_content.remove("creator");
}
_ => panic!("Unexpected room version {}", body.new_version)
_ => unreachable!("Validity of room version already checked")
}
create_event_content.insert(
"room_version".into(),

View file

@ -400,11 +400,7 @@ impl Service {
}
}
RoomVersionId::V11 => {
#[derive(Deserialize)]
struct Redaction {
redacts: Option<OwnedEventId>,
}
let content = serde_json::from_str::<Redaction>(pdu.content.get())
let content = serde_json::from_str::<RoomRedactionEventContent>(pdu.content.get())
.map_err(|_| {
Error::bad_database("Invalid content in redaction pdu.")
})?;
@ -680,11 +676,7 @@ impl Service {
.get_room_version(room_id)
.or_else(|_| {
if event_type == TimelineEventType::RoomCreate {
#[derive(Deserialize)]
struct RoomCreate {
room_version: RoomVersionId,
}
let content = serde_json::from_str::<RoomCreate>(content.get())
let content = serde_json::from_str::<RoomCreateEventContent>(content.get())
.expect("Invalid content in RoomCreate pdu.");
Ok(content.room_version)
} else {