From e2c914cc11f268bb6212e68e6b71b74255b24b97 Mon Sep 17 00:00:00 2001 From: girlbossceo Date: Sat, 29 Jul 2023 19:17:12 +0000 Subject: [PATCH] fix: s/ok_or/ok_or_else in relevant places Signed-off-by: girlbossceo --- src/api/client_server/room.rs | 12 ++++++++---- src/api/client_server/state.rs | 4 ++-- src/api/server_server.rs | 4 ++-- src/service/rooms/state/mod.rs | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/api/client_server/room.rs b/src/api/client_server/room.rs index 5c98028d..56bdf039 100644 --- a/src/api/client_server/room.rs +++ b/src/api/client_server/room.rs @@ -425,10 +425,14 @@ pub async fn get_room_event_route( ) -> Result { let sender_user = body.sender_user.as_ref().expect("user is authenticated"); - let event = services().rooms.timeline.get_pdu(&body.event_id)?.ok_or({ - warn!("Event not found, event ID: {:?}", &body.event_id); - Error::BadRequest(ErrorKind::NotFound, "Event not found.") - })?; + let event = services() + .rooms + .timeline + .get_pdu(&body.event_id)? + .ok_or_else(|| { + warn!("Event not found, event ID: {:?}", &body.event_id); + Error::BadRequest(ErrorKind::NotFound, "Event not found.") + })?; if !services().rooms.state_accessor.user_can_see_event( sender_user, diff --git a/src/api/client_server/state.rs b/src/api/client_server/state.rs index 6a374893..d6d39390 100644 --- a/src/api/client_server/state.rs +++ b/src/api/client_server/state.rs @@ -130,7 +130,7 @@ pub async fn get_state_events_for_key_route( .rooms .state_accessor .room_state_get(&body.room_id, &body.event_type, &body.state_key)? - .ok_or({ + .ok_or_else(|| { warn!( "State event {:?} not found in room {:?}", &body.event_type, &body.room_id @@ -169,7 +169,7 @@ pub async fn get_state_events_for_empty_key_route( .rooms .state_accessor .room_state_get(&body.room_id, &body.event_type, "")? - .ok_or({ + .ok_or_else(|| { warn!( "State event {:?} not found in room {:?}", &body.event_type, &body.room_id diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 8c54e92f..ca5b69d0 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -953,7 +953,7 @@ pub async fn get_event_route( .rooms .timeline .get_pdu_json(&body.event_id)? - .ok_or({ + .ok_or_else(|| { warn!("Event not found, event ID: {:?}", &body.event_id); Error::BadRequest(ErrorKind::NotFound, "Event not found.") })?; @@ -1196,7 +1196,7 @@ pub async fn get_event_authorization_route( .rooms .timeline .get_pdu_json(&body.event_id)? - .ok_or({ + .ok_or_else(|| { warn!("Event not found, event ID: {:?}", &body.event_id); Error::BadRequest(ErrorKind::NotFound, "Event not found.") })?; diff --git a/src/service/rooms/state/mod.rs b/src/service/rooms/state/mod.rs index 97906954..16e0a04d 100644 --- a/src/service/rooms/state/mod.rs +++ b/src/service/rooms/state/mod.rs @@ -342,7 +342,7 @@ impl Service { .transpose()?; let room_version = create_event_content .map(|create_event| create_event.room_version) - .ok_or({ + .ok_or_else(|| { warn!("Invalid room version for room {room_id}"); Error::BadDatabase("Invalid room version") })?;