The smokesignal.events web application
1use thiserror::Error;
2
3/// Represents errors that can occur during OAuth model operations.
4///
5/// These errors relate to OAuth authentication flows, session management,
6/// and cryptographic operations with JWT and JWK.
7#[derive(Debug, Error)]
8pub enum OAuthModelError {
9 /// Error when creating a DPoP secret from a JWK fails.
10 ///
11 /// This error occurs when attempting to convert a JSON Web Key (JWK)
12 /// into a secret key for DPoP (Demonstrating Proof-of-Possession) operations,
13 /// typically due to invalid key format or cryptographic errors.
14 #[error("error-smokesignal-oauth-model-1 Failed to create DPoP secret from JWK: {0:?}")]
15 DpopSecretFromJwkFailed(elliptic_curve::Error),
16
17 /// Error when the OAuth flow state is invalid.
18 ///
19 /// This error occurs when the state parameter in an OAuth flow
20 /// does not match the expected value or cannot be verified,
21 /// which could indicate a potential CSRF attack or session mismatch.
22 #[error("error-smokesignal-oauth-model-2 Invalid OAuth flow state")]
23 InvalidOAuthFlowState(),
24
25 /// Error when deserializing DPoP JWK from string fails.
26 ///
27 /// This error occurs when attempting to deserialize a string-encoded
28 /// JSON Web Key (JWK) for DPoP operations, typically due to invalid JSON format.
29 #[error("error-smokesignal-oauth-model-3 Failed to deserialize DPoP JWK: {0:?}")]
30 DpopJwkDeserializationFailed(serde_json::Error),
31}
32
33/// Represents errors that can occur during storage and database operations.
34#[derive(Debug, Error)]
35pub enum StorageError {
36 /// Error when a web session cannot be found in the database.
37 ///
38 /// This error occurs when attempting to retrieve a web session using an
39 /// invalid or expired session ID.
40 #[error("error-smokesignal-storage-1 Web session not found")]
41 WebSessionNotFound,
42
43 /// Error when a handle cannot be found in the database.
44 ///
45 /// This error occurs when attempting to retrieve a user handle that
46 /// doesn't exist in the system.
47 #[error("error-smokesignal-storage-2 Handle not found")]
48 HandleNotFound,
49
50 /// Error when a database record cannot be found.
51 ///
52 /// This error occurs when attempting to retrieve a specific record
53 /// using an ID or other identifier that doesn't exist in the database.
54 #[error("error-smokesignal-storage-3 Record not found: {0} {1:?}")]
55 RowNotFound(String, sqlx::Error),
56
57 /// Error when a database transaction cannot be committed.
58 ///
59 /// This error occurs when there is an issue finalizing a database
60 /// transaction, potentially causing data inconsistency.
61 #[error("error-smokesignal-storage-4 Cannot commit database transaction: {0:?}")]
62 CannotCommitDatabaseTransaction(sqlx::Error),
63
64 /// Error when a database transaction cannot be started.
65 ///
66 /// This error occurs when there is an issue initiating a database
67 /// transaction, typically due to connection issues or database constraints.
68 #[error("error-smokesignal-storage-5 Cannot begin database transaction: {0:?}")]
69 CannotBeginDatabaseTransaction(sqlx::Error),
70
71 /// Error when a database query cannot be executed.
72 ///
73 /// This error occurs when a SQL query fails to execute, typically due to
74 /// syntax errors, constraint violations, or database connectivity issues.
75 #[error("error-smokesignal-storage-6 Unable to execute query: {0:?}")]
76 UnableToExecuteQuery(sqlx::Error),
77
78 /// Error when an OAuth request cannot be found.
79 ///
80 /// This error occurs when attempting to retrieve an OAuth request
81 /// that doesn't exist or has expired.
82 #[error("error-smokesignal-storage-7 OAuth request not found")]
83 OAuthRequestNotFound,
84
85 /// Error when an RSVP cannot be found.
86 ///
87 /// This error occurs when attempting to retrieve an RSVP record
88 /// that doesn't exist in the database.
89 #[error("error-smokesignal-storage-8 RSVP not found")]
90 RSVPNotFound,
91
92 /// Error when an OAuth model operation fails.
93 ///
94 /// This error occurs when there's an issue with OAuth model operations,
95 /// such as token generation, validation, or storage.
96 #[error("error-smokesignal-storage-9 OAuth model error: {0}")]
97 OAuthModelError(#[from] OAuthModelError),
98
99 /// Error when a DID parameter is empty or invalid.
100 ///
101 /// This error occurs when a DID string is empty, which is not valid
102 /// for DID-based operations.
103 #[error("error-smokesignal-storage-10 DID cannot be empty")]
104 DidCannotBeEmpty,
105
106 /// Error when an OAuth state parameter is empty or invalid.
107 ///
108 /// This error occurs when an OAuth state string is empty, which is not valid
109 /// for OAuth operations.
110 #[error("error-smokesignal-storage-11 OAuth state cannot be empty")]
111 OAuthStateCannotBeEmpty,
112}
113
114/// Represents errors that can occur during cache operations.
115#[derive(Debug, Error)]
116pub enum CacheError {
117 /// Error when a cache pool cannot be created.
118 ///
119 /// This error occurs when the system fails to initialize the Redis
120 /// connection pool, typically due to configuration or connectivity issues.
121 #[error("error-smokesignal-cache-1 Failed to create cache pool: {0:?}")]
122 FailedToCreatePool(deadpool_redis::CreatePoolError),
123
124 /// Error when a cache connection cannot be obtained.
125 ///
126 /// This error occurs when the system fails to get a connection from
127 /// the Redis connection pool, typically due to pool exhaustion or connectivity issues.
128 #[error("error-smokesignal-cache-2 Failed to get connection: {0:?}")]
129 FailedToGetConnection(deadpool_redis::PoolError),
130
131 /// Error when a session cannot be placed in the refresh queue.
132 ///
133 /// This error occurs when the system fails to add a session to the
134 /// Redis-backed refresh queue, typically due to Redis errors or connectivity issues.
135 #[error("error-smokesignal-cache-3 Failed to place session group into refresh queue: {0:?}")]
136 FailedToPlaceInRefreshQueue(deadpool_redis::redis::RedisError),
137}
138
139#[derive(Debug, Error)]
140pub enum ContentError {
141 #[error("error-smokesignal-content-1 Invalid S3 URL format: {details}")]
142 /// Failed to parse S3 URL format from environment variable.
143 ConfigS3UrlInvalid {
144 /// Details about the S3 URL parsing error.
145 details: String,
146 },
147
148 #[error("error-smokesignal-content-2 File storage operation failed: {operation}")]
149 /// File storage operation failed.
150 StorageFileOperationFailed {
151 /// Description of the failed file operation.
152 operation: String,
153 },
154}