31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 1 | use std::sync::Arc; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 2 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 3 | use matrix_sdk::{ |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 4 | HttpError, RefreshTokenError, SendOutsideWasm, SyncOutsideWasm, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 5 | authentication::oauth::error::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 6 | OAuthAuthorizationCodeError, OAuthDiscoveryError, OAuthError, OAuthTokenRevocationError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 7 | RequestTokenError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 8 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 9 | encryption::{ |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 10 | identities::{ManualVerifyError, RequestVerificationError}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 11 | recovery::RecoveryError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 12 | secret_storage::{ImportError, SecretStorageError}, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 13 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 14 | }; |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 15 | #[cfg(feature = "serde")] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 16 | use serde::{Deserialize, Serialize}; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 17 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 18 | use crate::InteractiveAuthChallenge; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 19 | |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 20 | /// the sdk's `SendOutsideWasm` isn't an auto trait, so it can't go in a trait object |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 21 | #[cfg(not(target_family = "wasm"))] |
62fe32759529 | atagen | 2026-09-26 08:50 UTC | 22 | pub(crate) type SourceError = dyn std::error::Error + Send + Sync; |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 23 | #[cfg(target_family = "wasm")] |
62fe32759529 | atagen | 2026-09-26 08:50 UTC | 24 | pub(crate) type SourceError = dyn std::error::Error; |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 25 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 26 | /// the one thing that goes wrong, for commands and queries alike. match on `kind`, show `message` |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 27 | #[derive(Clone, Debug, thiserror::Error)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 28 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 29 | #[error("{message}")] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 30 | #[non_exhaustive] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 31 | pub struct Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 32 | pub kind: ErrorKind, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 33 | pub message: String, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 34 | /// set when the server wants interactive auth before it'll do the thing |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 35 | pub challenge: Option<Box<InteractiveAuthChallenge>>, |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 36 | /// set when the homeserver refused with a matrix error |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 37 | pub server: Option<ServerError>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 38 | #[source] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 39 | #[cfg_attr(feature = "serde", serde(skip))] |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 40 | source: Option<Arc<SourceError>>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 41 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 42 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 43 | #[derive(Clone, Copy, Debug, Eq, PartialEq)] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 44 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 45 | pub enum ErrorKind { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 46 | /// the engine stopped, or the task doing the work died, before answering |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 47 | Interrupted, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 48 | Unauthenticated, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 49 | InteractiveAuthRequired, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 50 | Invalid, |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 51 | /// the room's power levels don't let you |
9bd34e25bb86 | atagen | 2026-10-24 07:23 UTC | 52 | Forbidden, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 53 | RoomUnknown, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 54 | RoomNotOpen, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 55 | TimelineNotOpen, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 56 | RoomBusy, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 57 | QueueFull, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 58 | EmptyBody, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 59 | MediaUnknown, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 60 | MediaTooLarge, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 61 | MediaUnavailable, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 62 | VerificationInactive, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 63 | VerificationUnsupported, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 64 | NoCrossSigningIdentity, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 65 | RecoveryRejected, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 66 | Network, |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 67 | /// the homeserver wants us to slow down. try again later |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 68 | RateLimited, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 69 | Server, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 70 | Store, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 71 | Timeline, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 72 | Encryption, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 73 | Other, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 74 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 75 | |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 76 | /// the homeserver's own answer, worth showing a person as it stands |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 77 | #[derive(Clone, Debug, Eq, PartialEq)] |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 78 | #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 79 | #[non_exhaustive] |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 80 | pub struct ServerError { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 81 | pub status: u16, |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 82 | pub errcode: String, |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 83 | pub message: String, |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 84 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 85 | |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 86 | impl ServerError { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 87 | pub(crate) fn find(source: &(dyn std::error::Error + 'static)) -> Option<Self> { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 88 | let mut current = Some(source); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 89 | while let Some(error) = current { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 90 | let api = if let Some(error) = error.downcast_ref::<matrix_sdk::Error>() { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 91 | error.as_client_api_error() |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 92 | } else if let Some(error) = error.downcast_ref::<HttpError>() { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 93 | error.as_client_api_error() |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 94 | } else { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 95 | error.downcast_ref::<ruma::api::error::Error>() |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 96 | }; |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 97 | if let Some(api) = api |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 98 | && let ruma::api::error::ErrorBody::Standard(body) = &api.body |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 99 | { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 100 | return Some(Self { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 101 | status: api.status_code.as_u16(), |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 102 | errcode: body.kind.errcode().to_string(), |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 103 | message: body.message.clone(), |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 104 | }); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 105 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 106 | current = error.source(); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 107 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 108 | None |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 109 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 110 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 111 | |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 112 | impl std::fmt::Display for ServerError { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 113 | fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 114 | write!(formatter, "{} ({})", self.message, self.errcode) |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 115 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 116 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 117 | |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 118 | #[cfg(any(feature = "sqlite", feature = "indexeddb"))] |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 119 | pub(crate) fn classify(source: &(dyn std::error::Error + 'static)) -> ErrorKind { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 120 | let mut current = Some(source); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 121 | while let Some(error) = current { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 122 | if let Some(error) = error.downcast_ref::<matrix_sdk::Error>() { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 123 | return classify_sdk_error(error); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 124 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 125 | if let Some(error) = error.downcast_ref::<HttpError>() { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 126 | return classify_http_error(error); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 127 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 128 | if let Some(error) = error.downcast_ref::<OAuthError>() { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 129 | return classify_oauth_error(error); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 130 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 131 | if let Some(error) = error.downcast_ref::<RefreshTokenError>() { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 132 | return classify_refresh_token_error(error); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 133 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 134 | current = error.source(); |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 135 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 136 | ErrorKind::Other |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 137 | } |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 138 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 139 | impl Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 140 | pub(crate) fn new(kind: ErrorKind, message: impl Into<String>) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 141 | Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 142 | kind, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 143 | message: message.into(), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 144 | challenge: None, |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 145 | server: None, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 146 | source: None, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 147 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 148 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 149 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 150 | pub(crate) fn with_source( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 151 | kind: ErrorKind, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 152 | message: impl Into<String>, |
1fe480c16a3c | atagen | 2026-09-26 08:44 UTC | 153 | source: impl std::error::Error + SendOutsideWasm + SyncOutsideWasm + 'static, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 154 | ) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 155 | Self { |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 156 | server: ServerError::find(&source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 157 | source: Some(Arc::new(source)), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 158 | ..Self::new(kind, message) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 159 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 160 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 161 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 162 | pub(crate) fn interrupted() -> Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 163 | Self::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 164 | ErrorKind::Interrupted, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 165 | "the engine stopped before the operation finished", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 166 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 167 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 168 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 169 | pub(crate) fn room_unknown() -> Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 170 | Self::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 171 | ErrorKind::RoomUnknown, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 172 | "room is not available in the local store", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 173 | ) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 174 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 175 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 176 | pub(crate) fn interactive_auth(challenge: InteractiveAuthChallenge) -> Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 177 | Self { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 178 | challenge: Some(Box::new(challenge)), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 179 | ..Self::new( |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 180 | ErrorKind::InteractiveAuthRequired, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 181 | "interactive authentication is required", |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 182 | ) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 183 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 184 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 185 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 186 | pub(crate) fn from_sdk(message: impl Into<String>, source: matrix_sdk::Error) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 187 | Self::with_source(classify_sdk_error(&source), message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 188 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 189 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 190 | pub(crate) fn from_http(message: impl Into<String>, source: HttpError) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 191 | Self::with_source(classify_http_error(&source), message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 192 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 193 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 194 | pub(crate) fn from_refresh_token( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 195 | message: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 196 | source: RefreshTokenError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 197 | ) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 198 | Self::with_source(classify_refresh_token_error(&source), message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 199 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 200 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 201 | pub(crate) fn from_recovery(message: impl Into<String>, source: RecoveryError) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 202 | let kind = match &source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 203 | RecoveryError::Sdk(source) => classify_sdk_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 204 | RecoveryError::SecretStorage(SecretStorageError::Sdk(source)) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 205 | classify_sdk_error(source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 206 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 207 | RecoveryError::SecretStorage(SecretStorageError::ImportError { error, .. }) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 208 | match error { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 209 | ImportError::Sdk(source) => classify_sdk_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 210 | _ => ErrorKind::RecoveryRejected, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 211 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 212 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 213 | RecoveryError::SecretStorage(SecretStorageError::Verification(source)) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 214 | match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 215 | ManualVerifyError::Http(source) => classify_http_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 216 | _ => ErrorKind::RecoveryRejected, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 217 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 218 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 219 | RecoveryError::SecretStorage(SecretStorageError::SecretStorageKey(_)) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 220 | ErrorKind::RecoveryRejected |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 221 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 222 | RecoveryError::SecretStorage(SecretStorageError::Storage(_)) => ErrorKind::Store, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 223 | RecoveryError::BackupExistsOnServer | RecoveryError::SecretStorage(_) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 224 | ErrorKind::RecoveryRejected |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 225 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 226 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 227 | Self::with_source(kind, message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 228 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 229 | |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 230 | pub(crate) fn from_verification_request( |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 231 | message: impl Into<String>, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 232 | source: RequestVerificationError, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 233 | ) -> Self { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 234 | let kind = match &source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 235 | RequestVerificationError::Sdk(source) => classify_sdk_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 236 | RequestVerificationError::RoomCreation(_) => ErrorKind::Encryption, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 237 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 238 | Self::with_source(kind, message, source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 239 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 240 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 241 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 242 | impl PartialEq for Error { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 243 | fn eq(&self, other: &Self) -> bool { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 244 | self.kind == other.kind |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 245 | && self.message == other.message |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 246 | && self.challenge == other.challenge |
9a25b6ce66f4 | atagen | 2026-10-08 11:15 UTC | 247 | && self.server == other.server |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 248 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 249 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 250 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 251 | pub(crate) fn classify_sdk_error(source: &matrix_sdk::Error) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 252 | match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 253 | matrix_sdk::Error::Http(source) => classify_http_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 254 | matrix_sdk::Error::OAuth(source) => classify_oauth_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 255 | matrix_sdk::Error::AuthenticationRequired => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 256 | matrix_sdk::Error::BadCryptoStoreState |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 257 | | matrix_sdk::Error::CryptoStoreError(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 258 | | matrix_sdk::Error::CrossProcessLockError(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 259 | | matrix_sdk::Error::StateStore(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 260 | | matrix_sdk::Error::EventCacheStore(_) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 261 | | matrix_sdk::Error::MediaStore(_) => ErrorKind::Store, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 262 | matrix_sdk::Error::NoOlmMachine |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 263 | | matrix_sdk::Error::OlmError(_) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 264 | | matrix_sdk::Error::MegolmError(_) |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 265 | | matrix_sdk::Error::DecryptorError(_) => ErrorKind::Encryption, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 266 | matrix_sdk::Error::Media(_) => ErrorKind::MediaUnavailable, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 267 | matrix_sdk::Error::Timeout => ErrorKind::Network, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 268 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 269 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 270 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 271 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 272 | fn classify_http_error(source: &HttpError) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 273 | match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 274 | HttpError::Reqwest(_) => ErrorKind::Network, |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 275 | HttpError::Api(_) |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 276 | if source |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 277 | .as_client_api_error() |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 278 | .is_some_and(|api| api.status_code.as_u16() == 429) => |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 279 | { |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 280 | ErrorKind::RateLimited |
0291516d40b5 | atagen | 2026-10-22 08:31 UTC | 281 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 282 | HttpError::Api(_) => ErrorKind::Server, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 283 | HttpError::RefreshToken(source) => classify_refresh_token_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 284 | HttpError::Cached(source) => classify_http_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 285 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 286 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 287 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 288 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 289 | fn classify_refresh_token_error(source: &RefreshTokenError) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 290 | match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 291 | RefreshTokenError::RefreshTokenRequired => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 292 | RefreshTokenError::MatrixAuth(source) => classify_http_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 293 | RefreshTokenError::OAuth(source) => classify_oauth_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 294 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 295 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 296 | |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 297 | fn classify_oauth_error(source: &OAuthError) -> ErrorKind { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 298 | let classify_token_request_error = |source: &_| match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 299 | RequestTokenError::Request(_) => ErrorKind::Network, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 300 | RequestTokenError::ServerResponse(_) => ErrorKind::Unauthenticated, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 301 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 302 | }; |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 303 | match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 304 | OAuthError::Discovery(source) => match source { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 305 | OAuthDiscoveryError::Http(source) => classify_http_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 306 | OAuthDiscoveryError::Oidc(source) => classify_token_request_error(source), |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 307 | _ => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 308 | }, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 309 | OAuthError::RefreshToken(source) => classify_token_request_error(source), |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 310 | OAuthError::AuthorizationCode(OAuthAuthorizationCodeError::RequestToken(source)) => { |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 311 | classify_token_request_error(source) |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 312 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 313 | OAuthError::AuthorizationCode(_) => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 314 | OAuthError::Logout(source) => match source { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 315 | OAuthTokenRevocationError::Revoke(RequestTokenError::Request(_)) => ErrorKind::Network, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 316 | OAuthTokenRevocationError::Revoke(RequestTokenError::ServerResponse(_)) => { |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 317 | ErrorKind::Unauthenticated |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 318 | } |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 319 | _ => ErrorKind::Other, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 320 | }, |
31ce2453c82f | atagen | 2026-09-24 13:07 UTC | 321 | _ => ErrorKind::Unauthenticated, |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 322 | } |
96fdf90aacd6 | atagen | 2026-09-08 08:24 UTC | 323 | } |