-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(send_queue): Persist failed to send errors #4137
Changes from 1 commit
e769600
a5e5c02
e824fd2
3e65753
3511c69
93c4528
3586dd6
e304cb4
6d65a8d
5b911da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,10 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::{collections::BTreeMap, fmt}; | ||
use std::{ | ||
collections::{BTreeMap, HashMap}, | ||
fmt, | ||
}; | ||
|
||
use ruma::{ | ||
events::{AnyMessageLikeEvent, AnySyncTimelineEvent, AnyTimelineEvent}, | ||
|
@@ -703,6 +706,50 @@ impl From<SyncTimelineEventDeserializationHelperV0> for SyncTimelineEvent { | |
} | ||
} | ||
|
||
/// Represent a failed to send error of an event sent via the send_queue. | ||
/// These errors are not automatically retrievable, but yet some manual action | ||
/// can be taken before retry sending. | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] | ||
pub enum QueueWedgeError { | ||
/// This error occurs when there are some insecure devices in the room, and | ||
/// the current encryption setting prohibit sharing with them. | ||
BillCarsonFr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
InsecureDevices { | ||
/// The insecure devices as a Map of userID to deviceID. | ||
user_device_map: HashMap<String, Vec<String>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Outside the FFI layer, we're not using stringly-typing, so this would become a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see 3e65753 |
||
}, | ||
/// This error occurs when a previously verified user is not anymore, and | ||
/// the current encryption setting prohibit sharing when it happens. | ||
BillCarsonFr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
IdentityViolations { | ||
/// The users that are expected to be verified but are not. | ||
users: Vec<String>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see here #4137 (comment) |
||
}, | ||
/// It is required to set up cross-signing and properly verify the current | ||
/// session before sending. | ||
CrossVerificationRequired, | ||
/// Other errors. | ||
GenericApiError { msg: String }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see here #4137 (comment) |
||
} | ||
|
||
/// Simple display implementation that strips out userIds/DeviceIds to avoid | ||
/// accidental logging. | ||
impl fmt::Display for QueueWedgeError { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
QueueWedgeError::InsecureDevices { .. } => { | ||
f.write_str("There are insecure devices in the room") | ||
} | ||
QueueWedgeError::IdentityViolations { .. } => { | ||
f.write_str("Some users that were previously verified are not anymore") | ||
} | ||
QueueWedgeError::CrossVerificationRequired => { | ||
f.write_str("Own verification is required") | ||
} | ||
QueueWedgeError::GenericApiError { msg } => f.write_str(msg), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use assert_matches::assert_matches; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ use matrix_sdk::{ | |
}, | ||
Result, Room, | ||
}; | ||
use matrix_sdk_base::deserialized_responses::QueueWedgeError; | ||
use ruma::{ | ||
api::client::receipt::create_receipt::v3::ReceiptType as SendReceiptType, | ||
events::{ | ||
|
@@ -1262,9 +1263,9 @@ impl<P: RoomDataProvider> TimelineController<P> { | |
EventSendState::SendingFailed { | ||
// Put a dummy error in this case, since we're not persisting the errors | ||
// that occurred in previous sessions. | ||
error: Arc::new(matrix_sdk::Error::UnknownError(Box::new( | ||
MissingLocalEchoFailError, | ||
))), | ||
error: QueueWedgeError::GenericApiError { | ||
msg: MISSING_LOCAL_ECHO_FAIL_ERROR.into(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: for |
||
}, | ||
is_recoverable: false, | ||
}, | ||
) | ||
|
@@ -1521,9 +1522,8 @@ impl TimelineController { | |
} | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
#[error("local echo failed to send in a previous session")] | ||
struct MissingLocalEchoFailError; | ||
const MISSING_LOCAL_ECHO_FAIL_ERROR: &'static str = | ||
BillCarsonFr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"local echo failed to send in a previous session"; | ||
|
||
#[derive(Debug, Default)] | ||
pub(super) struct HandleManyEventsResult { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ use std::{ | |
use assert_matches2::{assert_let, assert_matches}; | ||
use matrix_sdk::{ | ||
config::{RequestConfig, StoreConfig}, | ||
deserialized_responses::QueueWedgeError, | ||
send_queue::{LocalEcho, LocalEchoContent, RoomSendQueueError, RoomSendQueueUpdate}, | ||
test_utils::{ | ||
events::EventFactory, logged_in_client, logged_in_client_with_server, set_client_session, | ||
|
@@ -471,8 +472,7 @@ async fn test_error_then_locally_reenabling() { | |
// seconds). | ||
// It's the same transaction id that's used to signal the send error. | ||
let error = assert_update!(watch => error { recoverable=true, txn=txn1 }); | ||
let error = error.as_client_api_error().unwrap(); | ||
assert_eq!(error.status_code, 500); | ||
assert_matches!(error, QueueWedgeError::GenericApiError { .. }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change justifies why we need to store the error itself, in the case of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed now, see here details #4137 (comment) |
||
|
||
sleep(Duration::from_millis(50)).await; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is related to the send queue, can we put it in the send queue file? Or is there a reason I'm missing to put it into deserialized_responses?
Also, should this use our common pattern of deriving
thiserror::Error
, to make it clear it's an error type, and would avoid the manual display impl? (uniffi also has anuniffi::Error
derive which could be convenient here)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Send Queue is in
matrix-sdk
and this error is persisted in the state storagematrix-sdk-base
.So it cannot be in the send_queue.rs file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, can we put those in
matrix-sdk-base
next to theQueueEvent
type, then? (or in a new file send_queue.rs somewhere in that crate)