mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-28 05:23:48 +03:00
Make Result alias usable with any error type
This commit is contained in:
parent
f2ef5677e0
commit
91afa1e0e0
5 changed files with 13 additions and 15 deletions
|
@ -60,7 +60,7 @@ use rocket::{get, tokio};
|
|||
pub async fn sync_events_route(
|
||||
db: DatabaseGuard,
|
||||
body: Ruma<sync_events::Request<'_>>,
|
||||
) -> std::result::Result<RumaResponse<sync_events::Response>, RumaResponse<UiaaResponse>> {
|
||||
) -> Result<RumaResponse<sync_events::Response>, RumaResponse<UiaaResponse>> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -182,7 +182,7 @@ async fn sync_helper(
|
|||
full_state: bool,
|
||||
timeout: Option<Duration>,
|
||||
// bool = caching allowed
|
||||
) -> std::result::Result<(sync_events::Response, bool), Error> {
|
||||
) -> Result<(sync_events::Response, bool), Error> {
|
||||
// TODO: match body.set_presence {
|
||||
db.rooms.edus.ping_presence(&sender_user)?;
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ impl WildCardedDomain {
|
|||
}
|
||||
impl std::str::FromStr for WildCardedDomain {
|
||||
type Err = std::convert::Infallible;
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// maybe do some domain validation?
|
||||
Ok(if s.starts_with("*.") {
|
||||
WildCardedDomain::WildCarded(s[1..].to_owned())
|
||||
|
@ -137,7 +137,7 @@ impl std::str::FromStr for WildCardedDomain {
|
|||
}
|
||||
}
|
||||
impl<'de> Deserialize<'de> for WildCardedDomain {
|
||||
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::de::Deserializer<'de>,
|
||||
{
|
||||
|
|
|
@ -485,7 +485,7 @@ impl Sending {
|
|||
kind: OutgoingKind,
|
||||
events: Vec<SendingEventType>,
|
||||
db: Arc<RwLock<Database>>,
|
||||
) -> std::result::Result<OutgoingKind, (OutgoingKind, Error)> {
|
||||
) -> Result<OutgoingKind, (OutgoingKind, Error)> {
|
||||
let db = db.read().await;
|
||||
|
||||
match &kind {
|
||||
|
|
|
@ -20,7 +20,7 @@ use {
|
|||
tracing::error,
|
||||
};
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
|
|
|
@ -65,7 +65,6 @@ use std::{
|
|||
mem,
|
||||
net::{IpAddr, SocketAddr},
|
||||
pin::Pin,
|
||||
result::Result as StdResult,
|
||||
sync::{Arc, RwLock, RwLockWriteGuard},
|
||||
time::{Duration, Instant, SystemTime},
|
||||
};
|
||||
|
@ -956,7 +955,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
|
|||
is_timeline_event: bool,
|
||||
db: &'a Database,
|
||||
pub_key_map: &'a RwLock<BTreeMap<String, BTreeMap<String, String>>>,
|
||||
) -> StdResult<Option<Vec<u8>>, String> {
|
||||
) -> Result<Option<Vec<u8>>, String> {
|
||||
match db.rooms.exists(room_id) {
|
||||
Ok(true) => {}
|
||||
_ => {
|
||||
|
@ -1137,8 +1136,7 @@ fn handle_outlier_pdu<'a>(
|
|||
value: BTreeMap<String, CanonicalJsonValue>,
|
||||
db: &'a Database,
|
||||
pub_key_map: &'a RwLock<BTreeMap<String, BTreeMap<String, String>>>,
|
||||
) -> AsyncRecursiveType<'a, StdResult<(Arc<PduEvent>, BTreeMap<String, CanonicalJsonValue>), String>>
|
||||
{
|
||||
) -> AsyncRecursiveType<'a, Result<(Arc<PduEvent>, BTreeMap<String, CanonicalJsonValue>), String>> {
|
||||
Box::pin(async move {
|
||||
// TODO: For RoomVersion6 we must check that Raw<..> is canonical do we anywhere?: https://matrix.org/docs/spec/rooms/v6#canonical-json
|
||||
|
||||
|
@ -1301,7 +1299,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
db: &Database,
|
||||
room_id: &RoomId,
|
||||
pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, String>>>,
|
||||
) -> StdResult<Option<Vec<u8>>, String> {
|
||||
) -> Result<Option<Vec<u8>>, String> {
|
||||
if let Ok(Some(pduid)) = db.rooms.get_pdu_id(&incoming_pdu.event_id) {
|
||||
return Ok(Some(pduid));
|
||||
}
|
||||
|
@ -1448,7 +1446,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
.map_err(|_| "Failed to get_or_create_shortstatekey".to_owned())?;
|
||||
Ok((shortstatekey, Arc::new(event_id)))
|
||||
})
|
||||
.collect::<StdResult<_, String>>()?,
|
||||
.collect::<Result<_, String>>()?,
|
||||
),
|
||||
Err(e) => {
|
||||
warn!("State resolution on prev events failed, either an event could not be found or deserialization: {}", e);
|
||||
|
@ -1630,7 +1628,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
.compress_state_event(*shortstatekey, id, &db.globals)
|
||||
.map_err(|_| "Failed to compress_state_event".to_owned())
|
||||
})
|
||||
.collect::<StdResult<_, _>>()?;
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
// 13. Check if the event passes auth based on the "current state" of the room, if not "soft fail" it
|
||||
debug!("starting soft fail auth check");
|
||||
|
@ -1750,7 +1748,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
.compress_state_event(*k, id, &db.globals)
|
||||
.map_err(|_| "Failed to compress_state_event.".to_owned())
|
||||
})
|
||||
.collect::<StdResult<_, _>>()?
|
||||
.collect::<Result<_, _>>()?
|
||||
} else {
|
||||
// We do need to force an update to this room's state
|
||||
update_state = true;
|
||||
|
@ -1812,7 +1810,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
.compress_state_event(shortstatekey, &event_id, &db.globals)
|
||||
.map_err(|_| "Failed to compress state event".to_owned())
|
||||
})
|
||||
.collect::<StdResult<_, _>>()?
|
||||
.collect::<Result<_, _>>()?
|
||||
};
|
||||
|
||||
// Set the new room state to the resolved state
|
||||
|
|
Loading…
Reference in a new issue