1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-11-04 16:28:53 +01:00

fix: do not panic on a JSON not containing the PDU

Do not panic on a JSON not containing the PDU when executing the parse-pdu admin command.
This commit is contained in:
M0dEx 2022-02-12 21:40:07 +01:00
parent 2b644ef7b7
commit d4217007fe
No known key found for this signature in database
GPG key ID: 0591F0EBE91EB914

View file

@ -354,24 +354,26 @@ fn process_admin_command(
let string = body[1..body.len() - 1].join("\n"); let string = body[1..body.len() - 1].join("\n");
match serde_json::from_str(&string) { match serde_json::from_str(&string) {
Ok(value) => { Ok(value) => {
let event_id = EventId::parse(format!( match ruma::signatures::reference_hash(&value, &RoomVersionId::V6) {
"${}", Ok(hash) => {
// Anything higher than version3 behaves the same let event_id = EventId::parse(format!("${}", hash));
ruma::signatures::reference_hash(&value, &RoomVersionId::V6)
.expect("ruma can calculate reference hashes")
))
.expect("ruma's reference hashes are valid event ids");
match serde_json::from_value::<PduEvent>( match serde_json::from_value::<PduEvent>(
serde_json::to_value(value).expect("value is json"), serde_json::to_value(value).expect("value is json"),
) { ) {
Ok(pdu) => RoomMessageEventContent::text_plain(format!( Ok(pdu) => RoomMessageEventContent::text_plain(format!(
"EventId: {:?}\n{:#?}", "EventId: {:?}\n{:#?}",
event_id, pdu event_id, pdu
)), )),
Err(e) => RoomMessageEventContent::text_plain(format!(
"EventId: {:?}\nCould not parse event: {}",
event_id, e
)),
}
}
Err(e) => RoomMessageEventContent::text_plain(format!( Err(e) => RoomMessageEventContent::text_plain(format!(
"EventId: {:?}\nCould not parse event: {}", "Could not parse PDU JSON: {:?}",
event_id, e e
)), )),
} }
} }