Skip to main content

arminius_lib_sync/syncv4/
error.rs

1// SPDX-FileCopyrightText: 2026 BWI GmbH
2//
3// SPDX-License-Identifier: Apache-2.0
4
5//! The various errors that can occur during a sync v4 (Simplified Sliding Sync) request handling.
6
7use arminius_lib_component::error::{FeatureNotImplemented, InternalServerError, MatrixApiError};
8use reqwest::StatusCode;
9use ruma::api::error::ErrorKind;
10
11use crate::sync_token::SyncTokenParseError;
12
13/// Maximum number of elements in the `lists` field of sync v4 requests.
14pub const MAX_LISTS_LEN: usize = 100;
15
16/// Maximum number of elements in the `room_subscriptions` field of sync v4
17/// requests.
18pub const MAX_SUBSCRIPTIONS_LEN: usize = 100;
19
20/// Enum containing all the possible errors of sync v4
21#[derive(Debug, thiserror::Error, MatrixApiError, arminius_lib_macros::FromDbError)]
22pub enum SyncV4Error {
23	/// An error from our side occurred
24	#[error(transparent)]
25	InternalServerError(#[from] InternalServerError),
26	/// A failure occurred when trying to parse the given `pos` into a
27	/// [`SyncToken`](crate::sync_token::SyncToken).
28	#[error(transparent)]
29	SyncTokenParseError(#[from] SyncTokenParseError),
30
31	/// Error thrown when we do not know the user's given `pos` parameter
32	#[matrix_api_error(status_code = StatusCode::BAD_REQUEST, error_kind = ErrorKind::UnknownPos)]
33	#[error("Unknown `pos` parameter provided")]
34	UnknownPos,
35	/// The `pos` parameter contains stream IDs from the future, which is not
36	/// possible.
37	#[matrix_api_error(status_code = StatusCode::BAD_REQUEST, error_kind = ErrorKind::InvalidParam)]
38	#[error("Invalid `pos` parameter provided")]
39	PosFromFuture,
40	/// The `lists` field of syncv4 requests MUST NOT have more than [`MAX_LISTS_LEN`] elements. See
41	/// <https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/4186-simplified-sliding-sync.md#top-level>.
42	#[matrix_api_error(status_code = StatusCode::BAD_REQUEST, error_kind = ErrorKind::InvalidParam)]
43	#[error("Requests `lists` cannot contain more than {MAX_LISTS_LEN} elements")]
44	TooManyLists,
45	/// The `room_subscriptions` field of syncv4 requests MUST NOT have more than
46	/// [`MAX_SUBSCRIPTIONS_LEN`] elements. See
47	/// <https://github.com/matrix-org/matrix-spec-proposals/blob/main/proposals/4186-simplified-sliding-sync.md#top-level>.
48	#[matrix_api_error(status_code = StatusCode::BAD_REQUEST, error_kind = ErrorKind::InvalidParam)]
49	#[error(
50		"Requests `room_subscriptions` cannot contain more than {MAX_SUBSCRIPTIONS_LEN} elements"
51	)]
52	TooManySubscriptions,
53
54	/// A list's range was reversed.
55	#[matrix_api_error(status_code = StatusCode::BAD_REQUEST, error_kind = ErrorKind::InvalidParam)]
56	#[error("Reversed range (a, b) where b < a")]
57	ReversedRange,
58
59	/// Some feature is not yet implemented.
60	#[error("Feature not implemented")]
61	FeatureNotImplemented(#[from] FeatureNotImplemented),
62}