replace panics on unknown room versions with errors
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
c70ce49ec0
commit
5c4b8ad7a3
3 changed files with 40 additions and 5 deletions
|
@ -147,7 +147,13 @@ pub async fn create_room_route(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
RoomVersionId::V11 => {} // V11 removed the "creator" key
|
RoomVersionId::V11 => {} // V11 removed the "creator" key
|
||||||
_ => panic!("Unexpected room version {}", room_version),
|
_ => {
|
||||||
|
warn!("Unexpected or unsupported room version {}", room_version);
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::BadJson,
|
||||||
|
"Unexpected or unsupported room version found",
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content.insert(
|
content.insert(
|
||||||
|
@ -172,7 +178,13 @@ pub async fn create_room_route(
|
||||||
| RoomVersionId::V9
|
| RoomVersionId::V9
|
||||||
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(sender_user.clone()),
|
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(sender_user.clone()),
|
||||||
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
||||||
_ => panic!("Unexpected room version {}", room_version),
|
_ => {
|
||||||
|
warn!("Unexpected or unsupported room version {}", room_version);
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::BadJson,
|
||||||
|
"Unexpected or unsupported room version found",
|
||||||
|
));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let mut content = serde_json::from_str::<CanonicalJsonObject>(
|
let mut content = serde_json::from_str::<CanonicalJsonObject>(
|
||||||
to_raw_value(&content)
|
to_raw_value(&content)
|
||||||
|
@ -673,7 +685,16 @@ pub async fn upgrade_room_route(
|
||||||
// "creator" key no longer exists in V11 rooms
|
// "creator" key no longer exists in V11 rooms
|
||||||
create_event_content.remove("creator");
|
create_event_content.remove("creator");
|
||||||
}
|
}
|
||||||
_ => panic!("Unexpected room version {}", body.new_version),
|
_ => {
|
||||||
|
warn!(
|
||||||
|
"Unexpected or unsupported room version {}",
|
||||||
|
body.new_version
|
||||||
|
);
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::BadJson,
|
||||||
|
"Unexpected or unsupported room version found",
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
create_event_content.insert(
|
create_event_content.insert(
|
||||||
|
|
|
@ -10,6 +10,7 @@ use std::fmt::Write;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
|
api::client::error::ErrorKind,
|
||||||
events::{
|
events::{
|
||||||
relation::InReplyTo,
|
relation::InReplyTo,
|
||||||
room::{
|
room::{
|
||||||
|
@ -30,6 +31,7 @@ use ruma::{
|
||||||
};
|
};
|
||||||
use serde_json::value::to_raw_value;
|
use serde_json::value::to_raw_value;
|
||||||
use tokio::sync::{mpsc, Mutex};
|
use tokio::sync::{mpsc, Mutex};
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
|
api::client_server::{leave_all_rooms, AUTO_GEN_PASSWORD_LENGTH},
|
||||||
|
@ -1420,7 +1422,13 @@ impl Service {
|
||||||
| RoomVersionId::V9
|
| RoomVersionId::V9
|
||||||
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(conduit_user.clone()),
|
| RoomVersionId::V10 => RoomCreateEventContent::new_v1(conduit_user.clone()),
|
||||||
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
RoomVersionId::V11 => RoomCreateEventContent::new_v11(),
|
||||||
_ => panic!("Unexpected room version {}", room_version),
|
_ => {
|
||||||
|
warn!("Unexpected or unsupported room version {}", room_version);
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::BadJson,
|
||||||
|
"Unexpected or unsupported room version found",
|
||||||
|
));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
content.federate = true;
|
content.federate = true;
|
||||||
|
|
|
@ -439,7 +439,13 @@ impl Service {
|
||||||
self.redact_pdu(redact_id, pdu)?;
|
self.redact_pdu(redact_id, pdu)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => panic!("Unexpected room version {}", room_version_id),
|
_ => {
|
||||||
|
warn!("Unexpected or unsupported room version {}", room_version_id);
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::BadJson,
|
||||||
|
"Unexpected or unsupported room version found",
|
||||||
|
));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
TimelineEventType::SpaceChild => {
|
TimelineEventType::SpaceChild => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue