arminius_lib_events/
errors.rs1use ruma::RoomVersionId;
8
9#[derive(Debug, thiserror::Error, PartialEq, Eq)]
11#[error("Tried to generate a stripped state event for a non-state event")]
12pub struct EventIsNotStateEvent;
13
14#[derive(Debug, thiserror::Error, Eq, PartialEq)]
16#[error("Unknown room version {0}")]
17pub struct UnknownRoomVersionError(pub RoomVersionId);
18
19#[derive(Debug, thiserror::Error, Eq, PartialEq)]
21#[error("Unknown room version {0}")]
22pub struct UnknownRoomVersionStringError(pub String);
23
24#[derive(Debug, thiserror::Error)]
26pub enum FromPduError {
27 #[error("Error deserializing database event: {0}")]
29 DeserializationError(#[from] serde_json::Error),
30 #[error(transparent)]
32 EventContextualizationError(#[from] EventContextualizationError),
33}
34
35#[expect(missing_docs, reason = "The error messages and names is documentation enough here")]
36#[derive(Debug, thiserror::Error)]
37pub enum EventContextualizationError {
38 #[error("Tried to create an event with more than 20 prev_events, but at most 20 are allowed")]
39 TooManyPrevEvents,
40 #[error("Tried to create an event with more than 10 auth_events, but at most 10 are allowed")]
41 TooManyAuthEvents,
42 #[error(transparent)]
43 MismatchedEventRefsError(#[from] MismatchedEventRefsError),
44 #[error("Error generating event ID: {0}")]
46 EventIdGenerationError(#[from] EventIdGenerationError),
47}
48
49#[expect(missing_docs, reason = "The error messages and names is documentation enough here")]
51#[derive(Debug, thiserror::Error)]
52pub enum MismatchedEventRefsError {
53 #[error("Invalid event refs: Expected V1 event refs, got V2")]
54 ExpectedV1GotV2,
55 #[error("Invalid event refs: Expected V2 event refs, got V1")]
56 ExpectedV2GotV1,
57}
58
59#[expect(missing_docs, reason = "The error messages and names is documentation enough here")]
61#[derive(Debug, thiserror::Error)]
62#[error("Could not generate event ID: {0}")]
63pub enum EventIdGenerationError {
64 #[error("Tried generating a V1 event ID, but no servername provided")]
65 V1MissingServerName,
66 #[error("Tried generating a servername for an invalid event")]
67 InvalidEvent(String),
68}
69
70#[derive(Debug, thiserror::Error)]
72pub enum AuthorizationError {
73 #[error("Could not convert event to PDU for auth checks: {0}")]
75 EventConversionError(#[from] EventConversionError),
76 #[error("Authorization check failed: {0}")]
78 AuthorizationFailed(String),
79}
80
81#[derive(Debug, thiserror::Error)]
83pub enum ValidationError {
84 #[error("Invalid signature: {0}")]
86 SignatureValidation(String),
87 #[error("JSON canonicalization failed: {0}")]
89 JsonCanonicalization(String),
90 #[error(transparent)]
92 JsonSerDe(#[from] JsonSerDeError),
93 #[error(transparent)]
95 AuthorizationError(#[from] AuthorizationError),
96 #[error("An error occurred when handling redacted data: {0}")]
99 Redaction(#[from] RedactionError),
100}
101
102#[derive(Debug, thiserror::Error)]
105pub enum RedactionError {
106 #[error(transparent)]
108 Ruma(#[from] ruma::canonical_json::CanonicalJsonFieldError),
109 #[error("Missing \"content\" field after redaction")]
112 MissingContent,
113}
114
115#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
117pub enum SigningError {
118 #[error("JSON canonicalization failed: {0}")]
120 JsonCanonicalization(String),
121 #[error("Signature error: {0}")]
123 SignatureCreation(String),
124 #[error("Invalid content: {0}")]
126 InvalidContent(String),
127}
128
129#[derive(Debug, thiserror::Error)]
132pub enum SigningValidationError {
133 #[error(transparent)]
135 SigningError(#[from] SigningError),
136 #[error(transparent)]
138 ValidationError(#[from] ValidationError),
139}
140
141#[derive(Debug, thiserror::Error)]
143pub enum JsonSerDeError {
144 #[error("Content deserialization error: {0}")]
146 ContentDeserialization(serde_json::Error),
147 #[error("JSON serialization error: {0}")]
149 JsonSerialization(serde_json::Error),
150}
151
152impl JsonSerDeError {
153 #[must_use]
156 pub fn custom_deserialization(msg: &str) -> Self {
157 Self::ContentDeserialization(<serde_json::Error as serde::de::Error>::custom(msg))
158 }
159}
160
161#[derive(Debug, thiserror::Error)]
163pub enum EventConversionError {
164 #[error(transparent)]
166 Json(#[from] JsonSerDeError),
167}