Skip to main content

ruma_common/api/error/
kind.rs

1#[cfg(feature = "unstable-msc4363")]
2use std::collections::BTreeSet;
3use std::str::FromStr;
4
5use as_variant::as_variant;
6use ruma_common::{
7    RoomVersionId,
8    api::error::{HeaderDeserializationError, HeaderSerializationError},
9    http_headers::{http_date_to_system_time, system_time_to_http_date},
10    serde::{JsonObject, StringEnum},
11};
12use web_time::{Duration, SystemTime};
13
14#[cfg(feature = "unstable-msc4406")]
15use crate::OwnedUserId;
16use crate::PrivOwnedStr;
17#[cfg(feature = "unstable-msc4363")]
18use crate::{OwnedAcr, api::OAuthClientScope};
19
20/// An enum for the error kind.
21///
22/// Items may contain additional information.
23#[derive(Clone, Debug, PartialEq, Eq)]
24#[non_exhaustive]
25// Please keep the variants sorted alphabetically.
26pub enum ErrorKind {
27    /// `M_APPSERVICE_LOGIN_UNSUPPORTED`
28    ///
29    /// An application service used the [`m.login.application_service`] type an endpoint from the
30    /// [legacy authentication API] in a way that is not supported by the homeserver, because the
31    /// server only supports the [OAuth 2.0 API].
32    ///
33    /// [`m.login.application_service`]: https://spec.matrix.org/v1.19/application-service-api/#server-admin-style-permissions
34    /// [legacy authentication API]: https://spec.matrix.org/v1.19/client-server-api/#legacy-api
35    /// [OAuth 2.0 API]: https://spec.matrix.org/v1.19/client-server-api/#oauth-20-api
36    AppserviceLoginUnsupported,
37
38    /// `M_BAD_ALIAS`
39    ///
40    /// One or more [room aliases] within the `m.room.canonical_alias` event do not point to the
41    /// room ID for which the state event is to be sent to.
42    ///
43    /// [room aliases]: https://spec.matrix.org/v1.19/client-server-api/#room-aliases
44    BadAlias,
45
46    /// `M_BAD_JSON`
47    ///
48    /// The request contained valid JSON, but it was malformed in some way, e.g. missing required
49    /// keys, invalid values for keys.
50    BadJson,
51
52    /// `M_BAD_STATE`
53    ///
54    /// The state change requested cannot be performed, such as attempting to unban a user who is
55    /// not banned.
56    BadState,
57
58    /// `M_BAD_STATUS`
59    ///
60    /// The application service returned a bad status.
61    BadStatus(BadStatusErrorData),
62
63    /// `M_CANNOT_LEAVE_SERVER_NOTICE_ROOM`
64    ///
65    /// The user is unable to reject an invite to join the [server notices] room.
66    ///
67    /// [server notices]: https://spec.matrix.org/v1.19/client-server-api/#server-notices
68    CannotLeaveServerNoticeRoom,
69
70    /// `M_CANNOT_OVERWRITE_MEDIA`
71    ///
72    /// The `PUT /_matrix/media/*/upload/{serverName}/{mediaId}` endpoint was called with a media ID
73    /// that already has content.
74    CannotOverwriteMedia,
75
76    /// `M_CAPTCHA_INVALID`
77    ///
78    /// The Captcha provided did not match what was expected.
79    CaptchaInvalid,
80
81    /// `M_CAPTCHA_NEEDED`
82    ///
83    /// A Captcha is required to complete the request.
84    CaptchaNeeded,
85
86    /// `M_CONCURRENT_WRITE`
87    ///
88    /// The sequence token provided when updating a rendezvous session
89    /// does not match the current sequence token.
90    #[cfg(feature = "unstable-msc4388")]
91    ConcurrentWrite,
92
93    /// `M_CONFLICTING_UNSUBSCRIPTION`
94    ///
95    /// Part of [MSC4306]: an automatic thread subscription has been skipped by the server, because
96    /// the user unsubsubscribed after the indicated subscribed-to event.
97    ///
98    /// [MSC4306]: https://github.com/matrix-org/matrix-spec-proposals/pull/4306
99    #[cfg(feature = "unstable-msc4306")]
100    ConflictingUnsubscription,
101
102    /// `M_CONNECTION_FAILED`
103    ///
104    /// The connection to the application service failed.
105    ConnectionFailed,
106
107    /// `M_CONNECTION_TIMEOUT`
108    ///
109    /// The connection to the application service timed out.
110    ConnectionTimeout,
111
112    /// `M_DELAY_TOO_LARGE`
113    ///
114    /// The requested delay of a [delayed event] exceeds the maximum allowed by the server.
115    ///
116    /// This uses the unstable prefix defined in [MSC4140].
117    ///
118    /// [delayed event]: https://github.com/matrix-org/matrix-spec-proposals/pull/4140
119    /// [MSC4140]: https://github.com/matrix-org/matrix-spec-proposals/pull/4140
120    #[cfg(feature = "unstable-msc4140")]
121    DelayTooLarge,
122
123    /// `M_DUPLICATE_ANNOTATION`
124    ///
125    /// The request is an attempt to send a [duplicate annotation].
126    ///
127    /// [duplicate annotation]: https://spec.matrix.org/v1.19/client-server-api/#avoiding-duplicate-annotations
128    DuplicateAnnotation,
129
130    /// `M_EXCLUSIVE`
131    ///
132    /// The resource being requested is reserved by an application service, or the application
133    /// service making the request has not created the resource.
134    Exclusive,
135
136    /// `M_FORBIDDEN`
137    ///
138    /// Forbidden access, e.g. joining a room without permission, failed login.
139    Forbidden,
140
141    /// `M_GUEST_ACCESS_FORBIDDEN`
142    ///
143    /// The room or resource does not permit [guests] to access it.
144    ///
145    /// [guests]: https://spec.matrix.org/v1.19/client-server-api/#guest-access
146    GuestAccessForbidden,
147
148    /// `M_INCOMPATIBLE_ROOM_VERSION`
149    ///
150    /// The client attempted to join a room that has a version the server does not support.
151    IncompatibleRoomVersion(IncompatibleRoomVersionErrorData),
152
153    /// `M_INSUFFICIENT_USER_AUTHENTICATION`
154    ///
155    /// The client needs to reauthenticate with the OAuth authorization server to use
156    /// this endpoint. ([MSC4363])
157    ///
158    /// [MSC4363]: https://github.com/matrix-org/matrix-spec-proposals/pull/4363
159    #[cfg(feature = "unstable-msc4363")]
160    InsufficientUserAuthentication(Box<InsufficientUserAuthenticationErrorData>),
161
162    /// `M_INVALID_PARAM`
163    ///
164    /// A parameter that was specified has the wrong value. For example, the server expected an
165    /// integer and instead received a string.
166    InvalidParam,
167
168    /// `M_INVALID_ROOM_STATE`
169    ///
170    /// The initial state implied by the parameters to the `POST /_matrix/client/*/createRoom`
171    /// request is invalid, e.g. the user's `power_level` is set below that necessary to set the
172    /// room name.
173    InvalidRoomState,
174
175    /// `M_INVALID_USERNAME`
176    ///
177    /// The desired user name is not valid.
178    InvalidUsername,
179
180    /// `M_INVITE_BLOCKED`
181    ///
182    /// The invite was interdicted by moderation tools or configured access controls without having
183    /// been witnessed by the invitee.
184    InviteBlocked,
185
186    /// `M_KEY_TOO_LARGE`
187    ///
188    /// The [profile] key in the request exceeds the maximum allowed length of 255 bytes.
189    ///
190    /// [profile]: https://spec.matrix.org/v1.19/client-server-api/#profiles
191    KeyTooLarge,
192
193    /// `M_LIMIT_EXCEEDED`
194    ///
195    /// The request has been refused due to [rate limiting]: too many requests have been sent in a
196    /// short period of time.
197    ///
198    /// [rate limiting]: https://spec.matrix.org/v1.19/client-server-api/#rate-limiting
199    LimitExceeded(LimitExceededErrorData),
200
201    /// `M_MISSING_PARAM`
202    ///
203    /// A required parameter was missing from the request.
204    MissingParam,
205
206    /// `M_MISSING_TOKEN`
207    ///
208    /// No [access token] was specified for the request, but one is required.
209    ///
210    /// [access token]: https://spec.matrix.org/v1.19/client-server-api/#client-authentication
211    MissingToken,
212
213    /// `M_NOT_FOUND`
214    ///
215    /// No resource was found for this request.
216    NotFound,
217
218    /// `M_NOT_IN_THREAD`
219    ///
220    /// Part of [MSC4306]: an automatic thread subscription was set to an event ID that isn't part
221    /// of the subscribed-to thread.
222    ///
223    /// [MSC4306]: https://github.com/matrix-org/matrix-spec-proposals/pull/4306
224    #[cfg(feature = "unstable-msc4306")]
225    NotInThread,
226
227    /// `M_NOT_JSON`
228    ///
229    /// The request did not contain valid JSON.
230    NotJson,
231
232    /// `M_NOT_YET_UPLOADED`
233    ///
234    /// An `mxc:` URI generated with the `POST /_matrix/media/*/create` endpoint was used and the
235    /// content is not yet available.
236    NotYetUploaded,
237
238    /// `M_PROFILE_TOO_LARGE`
239    ///
240    /// Storing the value in the request would make the [profile] exceed its maximum allowed size
241    /// of 64 KiB.
242    ///
243    /// [profile]: https://spec.matrix.org/v1.19/client-server-api/#profiles
244    ProfileTooLarge,
245
246    /// `M_RESOURCE_LIMIT_EXCEEDED`
247    ///
248    /// The request cannot be completed because the homeserver has reached a resource limit imposed
249    /// on it. For example, a homeserver held in a shared hosting environment may reach a resource
250    /// limit if it starts using too much memory or disk space.
251    ResourceLimitExceeded(ResourceLimitExceededErrorData),
252
253    /// `M_ROOM_IN_USE`
254    ///
255    /// The [room alias] specified in the `POST /_matrix/client/*/createRoom` request is already
256    /// taken.
257    ///
258    /// [room alias]: https://spec.matrix.org/v1.19/client-server-api/#room-aliases
259    RoomInUse,
260
261    /// `M_SENDER_IGNORED`
262    ///
263    /// The sender of the requested event is ignored by the requesting user. ([MSC])
264    ///
265    /// [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/4406
266    #[cfg(feature = "unstable-msc4406")]
267    SenderIgnored(SenderIgnoredErrorData),
268
269    /// `M_SERVER_NOT_TRUSTED`
270    ///
271    /// The client's request used a third-party server, e.g. identity server, that this server does
272    /// not trust.
273    ServerNotTrusted,
274
275    /// `M_THREEPID_AUTH_FAILED`
276    ///
277    /// Authentication could not be performed on the [third-party identifier].
278    ///
279    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
280    ThreepidAuthFailed,
281
282    /// `M_THREEPID_DENIED`
283    ///
284    /// The server does not permit this [third-party identifier]. This may happen if the server
285    /// only permits, for example, email addresses from a particular domain.
286    ///
287    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
288    ThreepidDenied,
289
290    /// `M_THREEPID_IN_USE`
291    ///
292    /// The [third-party identifier] is already in use by another user.
293    ///
294    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
295    ThreepidInUse,
296
297    /// `M_THREEPID_MEDIUM_NOT_SUPPORTED`
298    ///
299    /// The homeserver does not support adding a [third-party identifier] of the given medium.
300    ///
301    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
302    ThreepidMediumNotSupported,
303
304    /// `M_THREEPID_NOT_FOUND`
305    ///
306    /// No account matching the given [third-party identifier] could be found.
307    ///
308    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
309    ThreepidNotFound,
310
311    /// `M_TOKEN_INCORRECT`
312    ///
313    /// The token that the user entered to validate the session is incorrect.
314    TokenIncorrect,
315
316    /// `M_TOO_LARGE`
317    ///
318    /// The request or entity was too large.
319    TooLarge,
320
321    /// `M_UNABLE_TO_AUTHORISE_JOIN`
322    ///
323    /// The room is [restricted] and none of the conditions can be validated by the homeserver.
324    /// This can happen if the homeserver does not know about any of the rooms listed as
325    /// conditions, for example.
326    ///
327    /// [restricted]: https://spec.matrix.org/v1.19/client-server-api/#restricted-rooms
328    UnableToAuthorizeJoin,
329
330    /// `M_UNABLE_TO_GRANT_JOIN`
331    ///
332    /// A different server should be attempted for the join. This is typically because the resident
333    /// server can see that the joining user satisfies one or more conditions, such as in the case
334    /// of [restricted rooms], but the resident server would be unable to meet the authorization
335    /// rules.
336    ///
337    /// [restricted rooms]: https://spec.matrix.org/v1.19/client-server-api/#restricted-rooms
338    UnableToGrantJoin,
339
340    /// `M_UNACTIONABLE`
341    ///
342    /// The server does not want to handle the [federated report].
343    ///
344    /// [federated report]: https://github.com/matrix-org/matrix-spec-proposals/pull/3843
345    #[cfg(feature = "unstable-msc3843")]
346    Unactionable,
347
348    /// `M_UNAUTHORIZED`
349    ///
350    /// The request was not correctly authorized. Usually due to login failures.
351    Unauthorized,
352
353    /// `M_UNKNOWN`
354    ///
355    /// An unknown error has occurred.
356    Unknown,
357
358    /// `M_UNKNOWN_DEVICE`
359    ///
360    /// The device ID supplied by the application service does not belong to the user ID during
361    /// [identity assertion].
362    ///
363    /// [identity assertion]: https://spec.matrix.org/v1.19/application-service-api/#identity-assertion
364    UnknownDevice,
365
366    /// `M_UNKNOWN_POS`
367    ///
368    /// The sliding sync ([MSC4186]) connection was expired by the server.
369    ///
370    /// [MSC4186]: https://github.com/matrix-org/matrix-spec-proposals/pull/4186
371    #[cfg(feature = "unstable-msc4186")]
372    UnknownPos,
373
374    /// `M_UNKNOWN_TOKEN`
375    ///
376    /// The [access or refresh token] specified was not recognized.
377    ///
378    /// [access or refresh token]: https://spec.matrix.org/v1.19/client-server-api/#client-authentication
379    UnknownToken(UnknownTokenErrorData),
380
381    /// `M_UNRECOGNIZED`
382    ///
383    /// The server did not understand the request.
384    ///
385    /// This is expected to be returned with a 404 HTTP status code if the endpoint is not
386    /// implemented or a 405 HTTP status code if the endpoint is implemented, but the incorrect
387    /// HTTP method is used.
388    Unrecognized,
389
390    /// `M_UNSUPPORTED_ROOM_VERSION`
391    ///
392    /// The request to `POST /_matrix/client/*/createRoom` used a room version that the server does
393    /// not support.
394    UnsupportedRoomVersion,
395
396    /// `M_URL_NOT_SET`
397    ///
398    /// The application service doesn't have a URL configured.
399    UrlNotSet,
400
401    /// `M_USER_DEACTIVATED`
402    ///
403    /// The user ID associated with the request has been deactivated.
404    UserDeactivated,
405
406    /// `M_USER_IN_USE`
407    ///
408    /// The desired user ID is already taken.
409    UserInUse,
410
411    /// `M_USER_LIMIT_EXCEEDED`
412    ///
413    /// The request cannot be completed because the user has exceeded (or the request would cause
414    /// them to exceed) a limit associated with their account. For example, a user may have reached
415    /// their allocated storage quota, reached a maximum number of allowed rooms, devices, or other
416    /// account-scoped resources, or exceeded usage limits for specific features.
417    UserLimitExceeded(UserLimitExceededErrorData),
418
419    /// `M_USER_LOCKED`
420    ///
421    /// The account has been [locked] and cannot be used at this time.
422    ///
423    /// [locked]: https://spec.matrix.org/v1.19/client-server-api/#account-locking
424    UserLocked,
425
426    /// `M_USER_SUSPENDED`
427    ///
428    /// The account has been [suspended] and can only be used for limited actions at this time.
429    ///
430    /// [suspended]: https://spec.matrix.org/v1.19/client-server-api/#account-suspension
431    UserSuspended,
432
433    /// `M_WEAK_PASSWORD`
434    ///
435    /// The password was [rejected] by the server for being too weak.
436    ///
437    /// [rejected]: https://spec.matrix.org/v1.19/client-server-api/#password-management
438    WeakPassword,
439
440    /// `M_WRONG_ROOM_KEYS_VERSION`
441    ///
442    /// The version of the [room keys backup] provided in the request does not match the current
443    /// backup version.
444    ///
445    /// [room keys backup]: https://spec.matrix.org/v1.19/client-server-api/#server-side-key-backups
446    WrongRoomKeysVersion(WrongRoomKeysVersionErrorData),
447
448    #[doc(hidden)]
449    _Custom(Box<CustomErrorKind>),
450}
451
452impl ErrorKind {
453    /// Get the [`ErrorCode`] for this `ErrorKind`.
454    pub fn errcode(&self) -> ErrorCode {
455        match self {
456            ErrorKind::AppserviceLoginUnsupported => ErrorCode::AppserviceLoginUnsupported,
457            ErrorKind::BadAlias => ErrorCode::BadAlias,
458            ErrorKind::BadJson => ErrorCode::BadJson,
459            ErrorKind::BadState => ErrorCode::BadState,
460            ErrorKind::BadStatus(_) => ErrorCode::BadStatus,
461            ErrorKind::CannotLeaveServerNoticeRoom => ErrorCode::CannotLeaveServerNoticeRoom,
462            ErrorKind::CannotOverwriteMedia => ErrorCode::CannotOverwriteMedia,
463            ErrorKind::CaptchaInvalid => ErrorCode::CaptchaInvalid,
464            ErrorKind::CaptchaNeeded => ErrorCode::CaptchaNeeded,
465            #[cfg(feature = "unstable-msc4388")]
466            ErrorKind::ConcurrentWrite => ErrorCode::ConcurrentWrite,
467            #[cfg(feature = "unstable-msc4306")]
468            ErrorKind::ConflictingUnsubscription => ErrorCode::ConflictingUnsubscription,
469            ErrorKind::ConnectionFailed => ErrorCode::ConnectionFailed,
470            ErrorKind::ConnectionTimeout => ErrorCode::ConnectionTimeout,
471            #[cfg(feature = "unstable-msc4140")]
472            ErrorKind::DelayTooLarge => ErrorCode::DelayTooLarge,
473            ErrorKind::DuplicateAnnotation => ErrorCode::DuplicateAnnotation,
474            ErrorKind::Exclusive => ErrorCode::Exclusive,
475            ErrorKind::Forbidden => ErrorCode::Forbidden,
476            ErrorKind::GuestAccessForbidden => ErrorCode::GuestAccessForbidden,
477            ErrorKind::IncompatibleRoomVersion(_) => ErrorCode::IncompatibleRoomVersion,
478            #[cfg(feature = "unstable-msc4363")]
479            ErrorKind::InsufficientUserAuthentication(_) => {
480                ErrorCode::InsufficientUserAuthentication
481            }
482            ErrorKind::InvalidParam => ErrorCode::InvalidParam,
483            ErrorKind::InvalidRoomState => ErrorCode::InvalidRoomState,
484            ErrorKind::InvalidUsername => ErrorCode::InvalidUsername,
485            ErrorKind::InviteBlocked => ErrorCode::InviteBlocked,
486            ErrorKind::KeyTooLarge => ErrorCode::KeyTooLarge,
487            ErrorKind::LimitExceeded(_) => ErrorCode::LimitExceeded,
488            ErrorKind::MissingParam => ErrorCode::MissingParam,
489            ErrorKind::MissingToken => ErrorCode::MissingToken,
490            ErrorKind::NotFound => ErrorCode::NotFound,
491            #[cfg(feature = "unstable-msc4306")]
492            ErrorKind::NotInThread => ErrorCode::NotInThread,
493            ErrorKind::NotJson => ErrorCode::NotJson,
494            ErrorKind::NotYetUploaded => ErrorCode::NotYetUploaded,
495            ErrorKind::ProfileTooLarge => ErrorCode::ProfileTooLarge,
496            ErrorKind::ResourceLimitExceeded(_) => ErrorCode::ResourceLimitExceeded,
497            ErrorKind::RoomInUse => ErrorCode::RoomInUse,
498            #[cfg(feature = "unstable-msc4406")]
499            ErrorKind::SenderIgnored(_) => ErrorCode::SenderIgnored,
500            ErrorKind::ServerNotTrusted => ErrorCode::ServerNotTrusted,
501            ErrorKind::ThreepidAuthFailed => ErrorCode::ThreepidAuthFailed,
502            ErrorKind::ThreepidDenied => ErrorCode::ThreepidDenied,
503            ErrorKind::ThreepidInUse => ErrorCode::ThreepidInUse,
504            ErrorKind::ThreepidMediumNotSupported => ErrorCode::ThreepidMediumNotSupported,
505            ErrorKind::ThreepidNotFound => ErrorCode::ThreepidNotFound,
506            ErrorKind::TokenIncorrect => ErrorCode::TokenIncorrect,
507            ErrorKind::TooLarge => ErrorCode::TooLarge,
508            ErrorKind::UnableToAuthorizeJoin => ErrorCode::UnableToAuthorizeJoin,
509            ErrorKind::UnableToGrantJoin => ErrorCode::UnableToGrantJoin,
510            #[cfg(feature = "unstable-msc3843")]
511            ErrorKind::Unactionable => ErrorCode::Unactionable,
512            ErrorKind::Unauthorized => ErrorCode::Unauthorized,
513            ErrorKind::Unknown => ErrorCode::Unknown,
514            ErrorKind::UnknownDevice => ErrorCode::UnknownDevice,
515            #[cfg(feature = "unstable-msc4186")]
516            ErrorKind::UnknownPos => ErrorCode::UnknownPos,
517            ErrorKind::UnknownToken(_) => ErrorCode::UnknownToken,
518            ErrorKind::Unrecognized => ErrorCode::Unrecognized,
519            ErrorKind::UnsupportedRoomVersion => ErrorCode::UnsupportedRoomVersion,
520            ErrorKind::UrlNotSet => ErrorCode::UrlNotSet,
521            ErrorKind::UserDeactivated => ErrorCode::UserDeactivated,
522            ErrorKind::UserInUse => ErrorCode::UserInUse,
523            ErrorKind::UserLimitExceeded(_) => ErrorCode::UserLimitExceeded,
524            ErrorKind::UserLocked => ErrorCode::UserLocked,
525            ErrorKind::UserSuspended => ErrorCode::UserSuspended,
526            ErrorKind::WeakPassword => ErrorCode::WeakPassword,
527            ErrorKind::WrongRoomKeysVersion(_) => ErrorCode::WrongRoomKeysVersion,
528            ErrorKind::_Custom(kind) => kind.errcode.as_str().into(),
529        }
530    }
531
532    /// Get the JSON data for this `ErrorKind`, if it uses a custom error code.
533    pub fn custom_json_data(&self) -> Option<&JsonObject> {
534        as_variant!(self, Self::_Custom(error_kind) => &error_kind.data)
535    }
536}
537
538/// Data for the `M_BAD_STATUS` [`ErrorKind`].
539#[derive(Clone, Debug, Default, PartialEq, Eq)]
540#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
541pub struct BadStatusErrorData {
542    /// The HTTP status code of the response.
543    pub status: Option<http::StatusCode>,
544
545    /// The body of the response.
546    pub body: Option<String>,
547}
548
549impl BadStatusErrorData {
550    /// Construct a new empty `BadStatusErrorData`.
551    pub fn new() -> Self {
552        Self::default()
553    }
554}
555
556/// Data for the `M_INCOMPATIBLE_ROOM_VERSION` [`ErrorKind`].
557#[derive(Clone, Debug, PartialEq, Eq)]
558#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
559pub struct IncompatibleRoomVersionErrorData {
560    /// The room's version.
561    pub room_version: RoomVersionId,
562}
563
564impl IncompatibleRoomVersionErrorData {
565    /// Construct a new `IncompatibleRoomVersionErrorData` with the given room version.
566    pub fn new(room_version: RoomVersionId) -> Self {
567        Self { room_version }
568    }
569}
570
571/// Data for the `M_INSUFFICIENT_USER_AUTHENTICATION` [`ErrorKind`].
572#[derive(Clone, Debug, Default, PartialEq, Eq)]
573#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
574#[cfg(feature = "unstable-msc4363")]
575pub struct InsufficientUserAuthenticationErrorData {
576    /// The ACR values to supply to the auth server.
577    pub acr_values: Vec<OwnedAcr>,
578
579    /// The maximum number of seconds since the last authentication
580    /// until authentication must be performed again.
581    pub max_age: Option<Duration>,
582
583    /// The scopes required to access the resource.
584    pub scope: BTreeSet<OAuthClientScope>,
585}
586
587#[cfg(feature = "unstable-msc4363")]
588impl InsufficientUserAuthenticationErrorData {
589    /// Construct a new empty `InsufficientUserAuthenticationErrorData`.
590    pub fn new() -> Self {
591        Self::default()
592    }
593}
594
595/// Data for the `M_LIMIT_EXCEEDED` [`ErrorKind`].
596#[derive(Clone, Debug, Default, PartialEq, Eq)]
597#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
598pub struct LimitExceededErrorData {
599    /// How long a client should wait before they can try again.
600    pub retry_after: Option<RetryAfter>,
601}
602
603impl LimitExceededErrorData {
604    /// Construct a new empty `LimitExceededErrorData`.
605    pub fn new() -> Self {
606        Self::default()
607    }
608}
609
610/// How long a client should wait before it tries again.
611#[derive(Debug, Clone, Copy, PartialEq, Eq)]
612#[allow(clippy::exhaustive_enums)]
613pub enum RetryAfter {
614    /// The client should wait for the given duration.
615    ///
616    /// This variant should be preferred for backwards compatibility, as it will also populate the
617    /// `retry_after_ms` field in the body of the response.
618    Delay(Duration),
619    /// The client should wait for the given date and time.
620    DateTime(SystemTime),
621}
622
623impl TryFrom<&http::HeaderValue> for RetryAfter {
624    type Error = HeaderDeserializationError;
625
626    fn try_from(value: &http::HeaderValue) -> Result<Self, Self::Error> {
627        if value.as_bytes().iter().all(|b| b.is_ascii_digit()) {
628            // It should be a duration.
629            Ok(Self::Delay(Duration::from_secs(u64::from_str(value.to_str()?)?)))
630        } else {
631            // It should be a date.
632            Ok(Self::DateTime(http_date_to_system_time(value)?))
633        }
634    }
635}
636
637impl TryFrom<&RetryAfter> for http::HeaderValue {
638    type Error = HeaderSerializationError;
639
640    fn try_from(value: &RetryAfter) -> Result<Self, Self::Error> {
641        match value {
642            RetryAfter::Delay(duration) => Ok(duration.as_secs().into()),
643            RetryAfter::DateTime(time) => system_time_to_http_date(time),
644        }
645    }
646}
647
648/// Data for the `M_RESOURCE_LIMIT_EXCEEDED` [`ErrorKind`].
649#[derive(Clone, Debug, PartialEq, Eq)]
650#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
651pub struct ResourceLimitExceededErrorData {
652    /// A URI giving a contact method for the server administrator.
653    pub admin_contact: String,
654}
655
656impl ResourceLimitExceededErrorData {
657    /// Construct a new `ResourceLimitExceededErrorData` with the given admin contact URI.
658    pub fn new(admin_contact: String) -> Self {
659        Self { admin_contact }
660    }
661}
662
663/// Data for the `M_SENDER_IGNORED` [`ErrorKind`].
664#[cfg(feature = "unstable-msc4406")]
665#[derive(Clone, Debug, Default, PartialEq, Eq)]
666#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
667pub struct SenderIgnoredErrorData {
668    /// The user who sent the ignored event.
669    pub sender: Option<OwnedUserId>,
670}
671
672#[cfg(feature = "unstable-msc4406")]
673impl SenderIgnoredErrorData {
674    /// Construct a new empty `SenderIgnoredErrorData`.
675    pub fn new() -> Self {
676        Self::default()
677    }
678
679    /// Construct a new `SenderIgnoredErrorData` with the given sender user.
680    pub fn with_sender(sender: OwnedUserId) -> Self {
681        Self { sender: Some(sender) }
682    }
683}
684
685/// Data for the `M_UNKNOWN_TOKEN` [`ErrorKind`].
686#[derive(Clone, Debug, Default, PartialEq, Eq)]
687#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
688pub struct UnknownTokenErrorData {
689    /// If this is `true`, the client is in a "[soft logout]" state, i.e. the server requires
690    /// re-authentication but the session is not invalidated. The client can acquire a new
691    /// access token by specifying the device ID it is already using to the login API.
692    ///
693    /// [soft logout]: https://spec.matrix.org/v1.19/client-server-api/#soft-logout
694    pub soft_logout: bool,
695}
696
697impl UnknownTokenErrorData {
698    /// Construct a new `UnknownTokenErrorData` with `soft_logout` set to `false`.
699    pub fn new() -> Self {
700        Self::default()
701    }
702}
703
704/// Data for the `M_USER_LIMIT_EXCEEDED` [`ErrorKind`].
705#[derive(Clone, Debug, PartialEq, Eq)]
706#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
707pub struct UserLimitExceededErrorData {
708    /// A URI that the client can present to the user to provide more context on the encountered
709    /// limit and, if applicable, guidance on how to increase the limit.
710    ///
711    /// The homeserver MAY return different values depending on the type of limit reached.
712    pub info_uri: String,
713
714    /// Whether the specific limit encountered can be increased.
715    ///
716    /// If `true`, it indicates that the specific limit encountered can be increased, for example
717    /// by upgrading the user’s account tier. If `false`, the limit is a hard limit that cannot be
718    /// increased.
719    ///
720    /// Defaults to `false`.
721    pub can_upgrade: bool,
722}
723
724impl UserLimitExceededErrorData {
725    /// Construct a new `UserLimitExceededErrorData` with the given URI.
726    pub fn new(info_uri: String) -> Self {
727        Self { info_uri, can_upgrade: false }
728    }
729}
730
731/// Data for the `M_WRONG_ROOM_KEYS_VERSION` [`ErrorKind`].
732#[derive(Clone, Debug, PartialEq, Eq)]
733#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
734pub struct WrongRoomKeysVersionErrorData {
735    /// The currently active backup version.
736    pub current_version: String,
737}
738
739impl WrongRoomKeysVersionErrorData {
740    /// Construct a new `WrongRoomKeysVersionErrorData` with the given current active backup
741    /// version.
742    pub fn new(current_version: String) -> Self {
743        Self { current_version }
744    }
745}
746
747/// A custom error kind.
748#[doc(hidden)]
749#[derive(Clone, Debug, PartialEq, Eq)]
750pub struct CustomErrorKind {
751    /// The error code.
752    pub(super) errcode: String,
753
754    /// The data for the error.
755    pub(super) data: JsonObject,
756}
757
758/// The possible [error codes] defined in the Matrix spec.
759///
760/// [error codes]: https://spec.matrix.org/v1.19/client-server-api/#standard-error-response
761#[derive(Clone, StringEnum)]
762#[non_exhaustive]
763#[ruma_enum(rename_all(prefix = "M_", rule = "SCREAMING_SNAKE_CASE"))]
764// Please keep the variants sorted alphabetically.
765pub enum ErrorCode {
766    /// `M_APPSERVICE_LOGIN_UNSUPPORTED`
767    ///
768    /// An application service used the [`m.login.application_service`] type an endpoint from the
769    /// [legacy authentication API] in a way that is not supported by the homeserver, because the
770    /// server only supports the [OAuth 2.0 API].
771    ///
772    /// [`m.login.application_service`]: https://spec.matrix.org/v1.19/application-service-api/#server-admin-style-permissions
773    /// [legacy authentication API]: https://spec.matrix.org/v1.19/client-server-api/#legacy-api
774    /// [OAuth 2.0 API]: https://spec.matrix.org/v1.19/client-server-api/#oauth-20-api
775    AppserviceLoginUnsupported,
776
777    /// `M_BAD_ALIAS`
778    ///
779    /// One or more [room aliases] within the `m.room.canonical_alias` event do not point to the
780    /// room ID for which the state event is to be sent to.
781    ///
782    /// [room aliases]: https://spec.matrix.org/v1.19/client-server-api/#room-aliases
783    BadAlias,
784
785    /// `M_BAD_JSON`
786    ///
787    /// The request contained valid JSON, but it was malformed in some way, e.g. missing required
788    /// keys, invalid values for keys.
789    BadJson,
790
791    /// `M_BAD_STATE`
792    ///
793    /// The state change requested cannot be performed, such as attempting to unban a user who is
794    /// not banned.
795    BadState,
796
797    /// `M_BAD_STATUS`
798    ///
799    /// The application service returned a bad status.
800    BadStatus,
801
802    /// `M_CANNOT_LEAVE_SERVER_NOTICE_ROOM`
803    ///
804    /// The user is unable to reject an invite to join the [server notices] room.
805    ///
806    /// [server notices]: https://spec.matrix.org/v1.19/client-server-api/#server-notices
807    CannotLeaveServerNoticeRoom,
808
809    /// `M_CANNOT_OVERWRITE_MEDIA`
810    ///
811    /// The `PUT /_matrix/media/*/upload/{serverName}/{mediaId}` endpoint was called with a media ID
812    /// that already has content.
813    CannotOverwriteMedia,
814
815    /// `M_CAPTCHA_INVALID`
816    ///
817    /// The Captcha provided did not match what was expected.
818    CaptchaInvalid,
819
820    /// `M_CAPTCHA_NEEDED`
821    ///
822    /// A Captcha is required to complete the request.
823    CaptchaNeeded,
824
825    /// `M_CONCURRENT_WRITE`
826    ///
827    /// The sequence token provided when updating a rendezvous session
828    /// does not match the current sequence token.
829    ///
830    /// This uses the unstable prefix defined in [MSC4388].
831    ///
832    /// [MSC4388]: https://github.com/matrix-org/matrix-spec-proposals/pull/4388
833    #[cfg(feature = "unstable-msc4388")]
834    #[ruma_enum(rename = "IO_ELEMENT_MSC4388_CONCURRENT_WRITE")]
835    ConcurrentWrite,
836
837    /// `M_CONFLICTING_UNSUBSCRIPTION`
838    ///
839    /// Part of [MSC4306]: an automatic thread subscription has been skipped by the server, because
840    /// the user unsubsubscribed after the indicated subscribed-to event.
841    ///
842    /// [MSC4306]: https://github.com/matrix-org/matrix-spec-proposals/pull/4306
843    #[cfg(feature = "unstable-msc4306")]
844    #[ruma_enum(rename = "IO.ELEMENT.MSC4306.M_CONFLICTING_UNSUBSCRIPTION")]
845    ConflictingUnsubscription,
846
847    /// `M_CONNECTION_FAILED`
848    ///
849    /// The connection to the application service failed.
850    ConnectionFailed,
851
852    /// `M_CONNECTION_TIMEOUT`
853    ///
854    /// The connection to the application service timed out.
855    ConnectionTimeout,
856
857    /// `M_DELAY_TOO_LARGE`
858    ///
859    /// The requested delay of a [delayed event] exceeds the maximum allowed by the server.
860    ///
861    /// This uses the unstable prefix defined in [MSC4140].
862    ///
863    /// [delayed event]: https://github.com/matrix-org/matrix-spec-proposals/pull/4140
864    /// [MSC4140]: https://github.com/matrix-org/matrix-spec-proposals/pull/4140
865    #[cfg(feature = "unstable-msc4140")]
866    #[ruma_enum(rename = "ORG.MATRIX.MSC4140_DELAY_TOO_LARGE")]
867    DelayTooLarge,
868
869    /// `M_DUPLICATE_ANNOTATION`
870    ///
871    /// The request is an attempt to send a [duplicate annotation].
872    ///
873    /// [duplicate annotation]: https://spec.matrix.org/v1.19/client-server-api/#avoiding-duplicate-annotations
874    DuplicateAnnotation,
875
876    /// `M_EXCLUSIVE`
877    ///
878    /// The resource being requested is reserved by an application service, or the application
879    /// service making the request has not created the resource.
880    Exclusive,
881
882    /// `M_FORBIDDEN`
883    ///
884    /// Forbidden access, e.g. joining a room without permission, failed login.
885    Forbidden,
886
887    /// `M_GUEST_ACCESS_FORBIDDEN`
888    ///
889    /// The room or resource does not permit [guests] to access it.
890    ///
891    /// [guests]: https://spec.matrix.org/v1.19/client-server-api/#guest-access
892    GuestAccessForbidden,
893
894    /// `M_INCOMPATIBLE_ROOM_VERSION`
895    ///
896    /// The client attempted to join a room that has a version the server does not support.
897    IncompatibleRoomVersion,
898
899    /// `M_INSUFFICIENT_USER_AUTHENTICATION`
900    ///
901    /// The client needs to reauthenticate with the OAuth authorization server to use
902    /// this endpoint. ([MSC4363])
903    ///
904    /// [MSC4363]: https://github.com/matrix-org/matrix-spec-proposals/pull/4363
905    #[cfg(feature = "unstable-msc4363")]
906    #[ruma_enum(alias = "org.matrix.msc4363.M_INSUFFICIENT_USER_AUTHENTICATION")]
907    InsufficientUserAuthentication,
908
909    /// `M_INVALID_PARAM`
910    ///
911    /// A parameter that was specified has the wrong value. For example, the server expected an
912    /// integer and instead received a string.
913    InvalidParam,
914
915    /// `M_INVALID_ROOM_STATE`
916    ///
917    /// The initial state implied by the parameters to the `POST /_matrix/client/*/createRoom`
918    /// request is invalid, e.g. the user's `power_level` is set below that necessary to set the
919    /// room name.
920    InvalidRoomState,
921
922    /// `M_INVALID_USERNAME`
923    ///
924    /// The desired user name is not valid.
925    InvalidUsername,
926
927    /// `M_INVITE_BLOCKED`
928    ///
929    /// The invite was interdicted by moderation tools or configured access controls without having
930    /// been witnessed by the invitee.
931    ///
932    /// Unstable prefix intentionally shared with MSC4155 for compatibility.
933    #[ruma_enum(alias = "ORG.MATRIX.MSC4155.INVITE_BLOCKED")]
934    InviteBlocked,
935
936    /// `M_KEY_TOO_LARGE`
937    ///
938    /// The [profile] key in the request exceeds the maximum allowed length of 255 bytes.
939    ///
940    /// [profile]: https://spec.matrix.org/v1.19/client-server-api/#profiles
941    KeyTooLarge,
942
943    /// `M_LIMIT_EXCEEDED`
944    ///
945    /// The request has been refused due to [rate limiting]: too many requests have been sent in a
946    /// short period of time.
947    ///
948    /// [rate limiting]: https://spec.matrix.org/v1.19/client-server-api/#rate-limiting
949    LimitExceeded,
950
951    /// `M_MISSING_PARAM`
952    ///
953    /// A required parameter was missing from the request.
954    MissingParam,
955
956    /// `M_MISSING_TOKEN`
957    ///
958    /// No [access token] was specified for the request, but one is required.
959    ///
960    /// [access token]: https://spec.matrix.org/v1.19/client-server-api/#client-authentication
961    MissingToken,
962
963    /// `M_NOT_FOUND`
964    ///
965    /// No resource was found for this request.
966    NotFound,
967
968    /// `M_NOT_IN_THREAD`
969    ///
970    /// Part of [MSC4306]: an automatic thread subscription was set to an event ID that isn't part
971    /// of the subscribed-to thread.
972    ///
973    /// [MSC4306]: https://github.com/matrix-org/matrix-spec-proposals/pull/4306
974    #[cfg(feature = "unstable-msc4306")]
975    #[ruma_enum(rename = "IO.ELEMENT.MSC4306.M_NOT_IN_THREAD")]
976    NotInThread,
977
978    /// `M_NOT_JSON`
979    ///
980    /// The request did not contain valid JSON.
981    NotJson,
982
983    /// `M_NOT_YET_UPLOADED`
984    ///
985    /// An `mxc:` URI generated with the `POST /_matrix/media/*/create` endpoint was used and the
986    /// content is not yet available.
987    NotYetUploaded,
988
989    /// `M_PROFILE_TOO_LARGE`
990    ///
991    /// Storing the value in the request would make the [profile] exceed its maximum allowed size
992    /// of 64 KiB.
993    ///
994    /// [profile]: https://spec.matrix.org/v1.19/client-server-api/#profiles
995    ProfileTooLarge,
996
997    /// `M_RESOURCE_LIMIT_EXCEEDED`
998    ///
999    /// The request cannot be completed because the homeserver has reached a resource limit imposed
1000    /// on it. For example, a homeserver held in a shared hosting environment may reach a resource
1001    /// limit if it starts using too much memory or disk space.
1002    ResourceLimitExceeded,
1003
1004    /// `M_ROOM_IN_USE`
1005    ///
1006    /// The [room alias] specified in the `POST /_matrix/client/*/createRoom` request is already
1007    /// taken.
1008    ///
1009    /// [room alias]: https://spec.matrix.org/v1.19/client-server-api/#room-aliases
1010    RoomInUse,
1011
1012    /// `M_SENDER_IGNORED`
1013    ///
1014    /// The sender of the requested event is ignored by the requesting user. ([MSC])
1015    ///
1016    /// [MSC]: https://github.com/matrix-org/matrix-spec-proposals/pull/4406
1017    #[cfg(feature = "unstable-msc4406")]
1018    #[ruma_enum(rename = "UK.TIMEDOUT.MSC4406.SENDER_IGNORED")]
1019    SenderIgnored,
1020
1021    /// `M_SERVER_NOT_TRUSTED`
1022    ///
1023    /// The client's request used a third-party server, e.g. identity server, that this server does
1024    /// not trust.
1025    ServerNotTrusted,
1026
1027    /// `M_THREEPID_AUTH_FAILED`
1028    ///
1029    /// Authentication could not be performed on the [third-party identifier].
1030    ///
1031    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
1032    ThreepidAuthFailed,
1033
1034    /// `M_THREEPID_DENIED`
1035    ///
1036    /// The server does not permit this [third-party identifier]. This may happen if the server
1037    /// only permits, for example, email addresses from a particular domain.
1038    ///
1039    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
1040    ThreepidDenied,
1041
1042    /// `M_THREEPID_IN_USE`
1043    ///
1044    /// The [third-party identifier] is already in use by another user.
1045    ///
1046    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
1047    ThreepidInUse,
1048
1049    /// `M_THREEPID_MEDIUM_NOT_SUPPORTED`
1050    ///
1051    /// The homeserver does not support adding a [third-party identifier] of the given medium.
1052    ///
1053    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
1054    ThreepidMediumNotSupported,
1055
1056    /// `M_THREEPID_NOT_FOUND`
1057    ///
1058    /// No account matching the given [third-party identifier] could be found.
1059    ///
1060    /// [third-party identifier]: https://spec.matrix.org/v1.19/client-server-api/#adding-account-administrative-contact-information
1061    ThreepidNotFound,
1062
1063    /// `M_TOKEN_INCORRECT`
1064    ///
1065    /// The token that the user entered to validate the session is incorrect.
1066    TokenIncorrect,
1067
1068    /// `M_TOO_LARGE`
1069    ///
1070    /// The request or entity was too large.
1071    TooLarge,
1072
1073    /// `M_UNABLE_TO_AUTHORISE_JOIN`
1074    ///
1075    /// The room is [restricted] and none of the conditions can be validated by the homeserver.
1076    /// This can happen if the homeserver does not know about any of the rooms listed as
1077    /// conditions, for example.
1078    ///
1079    /// [restricted]: https://spec.matrix.org/v1.19/client-server-api/#restricted-rooms
1080    #[ruma_enum(rename = "M_UNABLE_TO_AUTHORISE_JOIN")]
1081    UnableToAuthorizeJoin,
1082
1083    /// `M_UNABLE_TO_GRANT_JOIN`
1084    ///
1085    /// A different server should be attempted for the join. This is typically because the resident
1086    /// server can see that the joining user satisfies one or more conditions, such as in the case
1087    /// of [restricted rooms], but the resident server would be unable to meet the authorization
1088    /// rules.
1089    ///
1090    /// [restricted rooms]: https://spec.matrix.org/v1.19/client-server-api/#restricted-rooms
1091    UnableToGrantJoin,
1092
1093    /// `M_UNACTIONABLE`
1094    ///
1095    /// The server does not want to handle the [federated report].
1096    ///
1097    /// [federated report]: https://github.com/matrix-org/matrix-spec-proposals/pull/3843
1098    #[cfg(feature = "unstable-msc3843")]
1099    Unactionable,
1100
1101    /// `M_UNAUTHORIZED`
1102    ///
1103    /// The request was not correctly authorized. Usually due to login failures.
1104    Unauthorized,
1105
1106    /// `M_UNKNOWN`
1107    ///
1108    /// An unknown error has occurred.
1109    Unknown,
1110
1111    /// `M_UNKNOWN_DEVICE`
1112    ///
1113    /// The device ID supplied by the application service does not belong to the user ID during
1114    /// [identity assertion].
1115    ///
1116    /// [identity assertion]: https://spec.matrix.org/v1.19/application-service-api/#identity-assertion
1117    UnknownDevice,
1118
1119    /// `M_UNKNOWN_POS`
1120    ///
1121    /// The sliding sync ([MSC4186]) connection was expired by the server.
1122    ///
1123    /// [MSC4186]: https://github.com/matrix-org/matrix-spec-proposals/pull/4186
1124    #[cfg(feature = "unstable-msc4186")]
1125    UnknownPos,
1126
1127    /// `M_UNKNOWN_TOKEN`
1128    ///
1129    /// The [access or refresh token] specified was not recognized.
1130    ///
1131    /// [access or refresh token]: https://spec.matrix.org/v1.19/client-server-api/#client-authentication
1132    UnknownToken,
1133
1134    /// `M_UNRECOGNIZED`
1135    ///
1136    /// The server did not understand the request.
1137    ///
1138    /// This is expected to be returned with a 404 HTTP status code if the endpoint is not
1139    /// implemented or a 405 HTTP status code if the endpoint is implemented, but the incorrect
1140    /// HTTP method is used.
1141    Unrecognized,
1142
1143    /// `M_UNSUPPORTED_ROOM_VERSION`
1144    UnsupportedRoomVersion,
1145
1146    /// `M_URL_NOT_SET`
1147    ///
1148    /// The application service doesn't have a URL configured.
1149    UrlNotSet,
1150
1151    /// `M_USER_DEACTIVATED`
1152    ///
1153    /// The user ID associated with the request has been deactivated.
1154    UserDeactivated,
1155
1156    /// `M_USER_IN_USE`
1157    ///
1158    /// The desired user ID is already taken.
1159    UserInUse,
1160
1161    /// `M_USER_LIMIT_EXCEEDED`
1162    ///
1163    /// The request cannot be completed because the user has exceeded (or the request would cause
1164    /// them to exceed) a limit associated with their account. For example, a user may have reached
1165    /// their allocated storage quota, reached a maximum number of allowed rooms, devices, or other
1166    /// account-scoped resources, or exceeded usage limits for specific features.
1167    UserLimitExceeded,
1168
1169    /// `M_USER_LOCKED`
1170    ///
1171    /// The account has been [locked] and cannot be used at this time.
1172    ///
1173    /// [locked]: https://spec.matrix.org/v1.19/client-server-api/#account-locking
1174    UserLocked,
1175
1176    /// `M_USER_SUSPENDED`
1177    ///
1178    /// The account has been [suspended] and can only be used for limited actions at this time.
1179    ///
1180    /// [suspended]: https://spec.matrix.org/v1.19/client-server-api/#account-suspension
1181    UserSuspended,
1182
1183    /// `M_WEAK_PASSWORD`
1184    ///
1185    /// The password was [rejected] by the server for being too weak.
1186    ///
1187    /// [rejected]: https://spec.matrix.org/v1.19/client-server-api/#password-management
1188    WeakPassword,
1189
1190    /// `M_WRONG_ROOM_KEYS_VERSION`
1191    ///
1192    /// The version of the [room keys backup] provided in the request does not match the current
1193    /// backup version.
1194    ///
1195    /// [room keys backup]: https://spec.matrix.org/v1.19/client-server-api/#server-side-key-backups
1196    WrongRoomKeysVersion,
1197
1198    #[doc(hidden)]
1199    _Custom(PrivOwnedStr),
1200}
1201
1202#[cfg(test)]
1203mod tests {
1204    use super::ErrorKind;
1205
1206    #[test]
1207    fn test_error_kind_type_size() {
1208        // There is no strict requirement for this type to be 40 bytes or smaller,
1209        // but it's been optimized by hand (Boxing the `_Custom` variant)
1210        // and it would be nice to keep track of any regressions.
1211        let size = size_of::<ErrorKind>();
1212        assert!(size <= 40, "size_of::<ErrorKind>() has regressed, is now {size}");
1213    }
1214}