ruma_identifiers_validation/
error.rs1use std::str::Utf8Error;
4
5#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9 #[error("identifier or required part of it is empty")]
11 Empty,
12
13 #[error("identifier contains invalid characters")]
15 InvalidCharacters,
16
17 #[error("invalid matrix ID: {0}")]
19 InvalidMatrixId(#[from] MatrixIdError),
20
21 #[error("invalid matrix.to URI: {0}")]
23 InvalidMatrixToUri(#[from] MatrixToError),
24
25 #[error("invalid matrix URI: {0}")]
27 InvalidMatrixUri(#[from] MatrixUriError),
28
29 #[error("invalid Matrix Content URI: {0}")]
31 InvalidMxcUri(#[from] MxcUriError),
32
33 #[error("invalid VoIP version ID: {0}")]
35 InvalidVoipVersionId(#[from] VoipVersionIdError),
36
37 #[error("server name is not a valid IP address or domain name")]
39 InvalidServerName,
40
41 #[error("invalid UTF-8")]
43 InvalidUtf8,
44
45 #[error("ID exceeds 255 bytes")]
47 MaximumLengthExceeded,
48
49 #[error("required colon is missing")]
52 MissingColon,
53
54 #[error("leading sigil is incorrect or missing")]
56 MissingLeadingSigil,
57}
58
59impl From<Utf8Error> for Error {
60 fn from(_: Utf8Error) -> Self {
61 Self::InvalidUtf8
62 }
63}
64
65#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
67#[non_exhaustive]
68pub enum MxcUriError {
69 #[error("MXC URI schema was not mxc://")]
71 WrongSchema,
72
73 #[error("MXC URI does not have first slash")]
75 MissingSlash,
76
77 #[error("Media Identifier malformed, invalid characters")]
82 MediaIdMalformed,
83
84 #[error("invalid Server Name")]
86 ServerNameMalformed,
87}
88
89#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
91#[non_exhaustive]
92pub enum MatrixIdError {
93 #[error("invalid number of parts")]
95 InvalidPartsNumber,
96
97 #[error("missing room ID or alias")]
99 MissingRoom,
100
101 #[error("no identifier")]
103 NoIdentifier,
104
105 #[error("too many identifiers")]
107 TooManyIdentifiers,
108
109 #[error("unknown identifier")]
111 UnknownIdentifier,
112
113 #[error("unknown identifier pair")]
115 UnknownIdentifierPair,
116
117 #[error("unknown identifier type")]
119 UnknownType,
120}
121
122#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
124#[non_exhaustive]
125pub enum MatrixToError {
126 #[error("given string is not a valid URL")]
128 InvalidUrl,
129
130 #[error("base URL is not https://matrix.to/#/")]
132 WrongBaseUrl,
133
134 #[error("unknown additional argument")]
136 UnknownArgument,
137}
138
139#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
141#[non_exhaustive]
142pub enum MatrixUriError {
143 #[error("scheme is not 'matrix:'")]
145 WrongScheme,
146
147 #[error("too many actions")]
149 TooManyActions,
150
151 #[error("unknown query item")]
153 UnknownQueryItem,
154}
155
156#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, thiserror::Error)]
158#[non_exhaustive]
159pub enum VoipVersionIdError {
160 #[error("UInt value is not 0")]
162 WrongUintValue,
163}
164
165#[cfg(test)]
166mod tests {
167 use std::mem::size_of;
168
169 use super::Error;
170
171 #[test]
172 fn small_error_type() {
173 assert!(size_of::<Error>() <= 8);
174 }
175}