Improve error messages for missing auth event and invalid join validations.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use ruma::{CanonicalJsonObject, OwnedEventId, RoomVersionId};
|
use ruma::{CanonicalJsonObject, OwnedEventId, RoomVersionId};
|
||||||
use serde_json::value::RawValue as RawJsonValue;
|
use serde_json::value::RawValue as RawJsonValue;
|
||||||
|
|
||||||
use crate::{Result, err, matrix::room_version};
|
use crate::{Result, debug_error, err, matrix::room_version};
|
||||||
|
|
||||||
/// Generates a correct eventId for the incoming pdu.
|
/// Generates a correct eventId for the incoming pdu.
|
||||||
///
|
///
|
||||||
@@ -12,7 +12,8 @@ pub fn gen_event_id_canonical_json(
|
|||||||
room_version_id: &RoomVersionId,
|
room_version_id: &RoomVersionId,
|
||||||
) -> Result<(OwnedEventId, CanonicalJsonObject)> {
|
) -> Result<(OwnedEventId, CanonicalJsonObject)> {
|
||||||
let value: CanonicalJsonObject = serde_json::from_str(pdu.get())
|
let value: CanonicalJsonObject = serde_json::from_str(pdu.get())
|
||||||
.map_err(|e| err!(BadServerResponse(warn!("Error parsing incoming event: {e:?}"))))?;
|
.map_err(|e| err!(BadServerResponse(warn!("Error parsing canonical event: {e}"))))
|
||||||
|
.inspect_err(|e| debug_error!("{pdu:#?} {e:?}"))?;
|
||||||
|
|
||||||
let event_id = gen_event_id(&value, room_version_id)?;
|
let event_id = gen_event_id(&value, room_version_id)?;
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ mod room_member;
|
|||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use futures::{
|
use futures::{
|
||||||
FutureExt, TryFutureExt, TryStreamExt,
|
FutureExt, TryStreamExt,
|
||||||
future::{join3, try_join},
|
future::{join3, try_join},
|
||||||
};
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
@@ -119,9 +119,10 @@ where
|
|||||||
let seen_auth_types = incoming_event
|
let seen_auth_types = incoming_event
|
||||||
.auth_events()
|
.auth_events()
|
||||||
.try_stream()
|
.try_stream()
|
||||||
.and_then(|event_id: &EventId| {
|
.and_then(async |event_id: &EventId| match fetch_event(event_id.to_owned()).await {
|
||||||
fetch_event(event_id.to_owned())
|
| Ok(auth_event) => Ok(auth_event),
|
||||||
.map_err(|_| err!(Request(NotFound("failed to find auth event"))))
|
| Err(e) if e.is_not_found() => Err!(Request(NotFound("auth event {event_id}: {e}"))),
|
||||||
|
| Err(e) => Err(e),
|
||||||
})
|
})
|
||||||
.ready_try_fold(seen_auth_types, |mut seen_auth_types, auth_event| {
|
.ready_try_fold(seen_auth_types, |mut seen_auth_types, auth_event| {
|
||||||
let event_id = auth_event.event_id();
|
let event_id = auth_event.event_id();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
|
use std::{borrow::Borrow, collections::HashMap, iter::once, sync::Arc};
|
||||||
|
|
||||||
use futures::{FutureExt, StreamExt, TryFutureExt, pin_mut};
|
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, pin_mut};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, OwnedUserId, RoomId, RoomVersionId,
|
CanonicalJsonObject, CanonicalJsonValue, OwnedServerName, OwnedUserId, RoomId, RoomVersionId,
|
||||||
UserId,
|
UserId,
|
||||||
@@ -16,7 +16,7 @@ use ruma::{
|
|||||||
room::{AllowRule, JoinRule},
|
room::{AllowRule, JoinRule},
|
||||||
};
|
};
|
||||||
use tuwunel_core::{
|
use tuwunel_core::{
|
||||||
Err, Result, debug, debug_info, debug_warn, err, error, implement, info,
|
Err, Result, debug, debug_error, debug_info, debug_warn, err, error, implement, info,
|
||||||
matrix::{
|
matrix::{
|
||||||
event::{gen_event_id, gen_event_id_canonical_json},
|
event::{gen_event_id, gen_event_id_canonical_json},
|
||||||
room_version,
|
room_version,
|
||||||
@@ -366,6 +366,7 @@ pub async fn join_remote(
|
|||||||
.server_keys
|
.server_keys
|
||||||
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
||||||
})
|
})
|
||||||
|
.inspect_err(|e| debug_error!("Invalid send_join state event: {e:?}"))
|
||||||
.ready_filter_map(Result::ok)
|
.ready_filter_map(Result::ok)
|
||||||
.fold(HashMap::new(), async |mut state, (event_id, mut value)| {
|
.fold(HashMap::new(), async |mut state, (event_id, mut value)| {
|
||||||
let pdu = if value["type"] == "m.room.create" {
|
let pdu = if value["type"] == "m.room.create" {
|
||||||
@@ -419,6 +420,7 @@ pub async fn join_remote(
|
|||||||
.server_keys
|
.server_keys
|
||||||
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
.validate_and_add_event_id_no_fetch(pdu, &room_version_id)
|
||||||
})
|
})
|
||||||
|
.inspect_err(|e| debug_error!("Invalid send_join auth_chain event: {e:?}"))
|
||||||
.ready_filter_map(Result::ok)
|
.ready_filter_map(Result::ok)
|
||||||
.ready_for_each(|(event_id, mut value)| {
|
.ready_for_each(|(event_id, mut value)| {
|
||||||
if !value.contains_key("room_id") {
|
if !value.contains_key("room_id") {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ type Parsed = (OwnedRoomId, OwnedEventId, CanonicalJsonObject);
|
|||||||
#[implement(super::Service)]
|
#[implement(super::Service)]
|
||||||
pub async fn parse_incoming_pdu(&self, pdu: &RawJsonValue) -> Result<Parsed> {
|
pub async fn parse_incoming_pdu(&self, pdu: &RawJsonValue) -> Result<Parsed> {
|
||||||
let value = serde_json::from_str::<CanonicalJsonObject>(pdu.get()).map_err(|e| {
|
let value = serde_json::from_str::<CanonicalJsonObject>(pdu.get()).map_err(|e| {
|
||||||
err!(BadServerResponse(debug_warn!("Error parsing incoming event {e:?}")))
|
err!(BadServerResponse(debug_error!("Error parsing incoming event: {e} {pdu:#?}")))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let room_id: OwnedRoomId = value
|
let room_id: OwnedRoomId = value
|
||||||
|
|||||||
Reference in New Issue
Block a user