use thiserror::Error; /// Represents errors that can occur during OAuth model operations. /// /// These errors relate to OAuth authentication flows, session management, /// and cryptographic operations with JWT and JWK. #[derive(Debug, Error)] pub enum OAuthModelError { /// Error when creating a DPoP secret from a JWK fails. /// /// This error occurs when attempting to convert a JSON Web Key (JWK) /// into a secret key for DPoP (Demonstrating Proof-of-Possession) operations, /// typically due to invalid key format or cryptographic errors. #[error("error-smokesignal-oauth-model-1 Failed to create DPoP secret from JWK: {0:?}")] DpopSecretFromJwkFailed(elliptic_curve::Error), /// Error when the OAuth flow state is invalid. /// /// This error occurs when the state parameter in an OAuth flow /// does not match the expected value or cannot be verified, /// which could indicate a potential CSRF attack or session mismatch. #[error("error-smokesignal-oauth-model-2 Invalid OAuth flow state")] InvalidOAuthFlowState(), /// Error when deserializing DPoP JWK from string fails. /// /// This error occurs when attempting to deserialize a string-encoded /// JSON Web Key (JWK) for DPoP operations, typically due to invalid JSON format. #[error("error-smokesignal-oauth-model-3 Failed to deserialize DPoP JWK: {0:?}")] DpopJwkDeserializationFailed(serde_json::Error), } /// Represents errors that can occur during storage and database operations. #[derive(Debug, Error)] pub enum StorageError { /// Error when a web session cannot be found in the database. /// /// This error occurs when attempting to retrieve a web session using an /// invalid or expired session ID. #[error("error-smokesignal-storage-1 Web session not found")] WebSessionNotFound, /// Error when a handle cannot be found in the database. /// /// This error occurs when attempting to retrieve a user handle that /// doesn't exist in the system. #[error("error-smokesignal-storage-2 Handle not found")] HandleNotFound, /// Error when a database record cannot be found. /// /// This error occurs when attempting to retrieve a specific record /// using an ID or other identifier that doesn't exist in the database. #[error("error-smokesignal-storage-3 Record not found: {0} {1:?}")] RowNotFound(String, sqlx::Error), /// Error when a database transaction cannot be committed. /// /// This error occurs when there is an issue finalizing a database /// transaction, potentially causing data inconsistency. #[error("error-smokesignal-storage-4 Cannot commit database transaction: {0:?}")] CannotCommitDatabaseTransaction(sqlx::Error), /// Error when a database transaction cannot be started. /// /// This error occurs when there is an issue initiating a database /// transaction, typically due to connection issues or database constraints. #[error("error-smokesignal-storage-5 Cannot begin database transaction: {0:?}")] CannotBeginDatabaseTransaction(sqlx::Error), /// Error when a database query cannot be executed. /// /// This error occurs when a SQL query fails to execute, typically due to /// syntax errors, constraint violations, or database connectivity issues. #[error("error-smokesignal-storage-6 Unable to execute query: {0:?}")] UnableToExecuteQuery(sqlx::Error), /// Error when an OAuth request cannot be found. /// /// This error occurs when attempting to retrieve an OAuth request /// that doesn't exist or has expired. #[error("error-smokesignal-storage-7 OAuth request not found")] OAuthRequestNotFound, /// Error when an RSVP cannot be found. /// /// This error occurs when attempting to retrieve an RSVP record /// that doesn't exist in the database. #[error("error-smokesignal-storage-8 RSVP not found")] RSVPNotFound, /// Error when an OAuth model operation fails. /// /// This error occurs when there's an issue with OAuth model operations, /// such as token generation, validation, or storage. #[error("error-smokesignal-storage-9 OAuth model error: {0}")] OAuthModelError(#[from] OAuthModelError), /// Error when a DID parameter is empty or invalid. /// /// This error occurs when a DID string is empty, which is not valid /// for DID-based operations. #[error("error-smokesignal-storage-10 DID cannot be empty")] DidCannotBeEmpty, /// Error when an OAuth state parameter is empty or invalid. /// /// This error occurs when an OAuth state string is empty, which is not valid /// for OAuth operations. #[error("error-smokesignal-storage-11 OAuth state cannot be empty")] OAuthStateCannotBeEmpty, } /// Represents errors that can occur during cache operations. #[derive(Debug, Error)] pub enum CacheError { /// Error when a cache pool cannot be created. /// /// This error occurs when the system fails to initialize the Redis /// connection pool, typically due to configuration or connectivity issues. #[error("error-smokesignal-cache-1 Failed to create cache pool: {0:?}")] FailedToCreatePool(deadpool_redis::CreatePoolError), /// Error when a cache connection cannot be obtained. /// /// This error occurs when the system fails to get a connection from /// the Redis connection pool, typically due to pool exhaustion or connectivity issues. #[error("error-smokesignal-cache-2 Failed to get connection: {0:?}")] FailedToGetConnection(deadpool_redis::PoolError), /// Error when a session cannot be placed in the refresh queue. /// /// This error occurs when the system fails to add a session to the /// Redis-backed refresh queue, typically due to Redis errors or connectivity issues. #[error("error-smokesignal-cache-3 Failed to place session group into refresh queue: {0:?}")] FailedToPlaceInRefreshQueue(deadpool_redis::redis::RedisError), } #[derive(Debug, Error)] pub enum ContentError { #[error("error-smokesignal-content-1 Invalid S3 URL format: {details}")] /// Failed to parse S3 URL format from environment variable. ConfigS3UrlInvalid { /// Details about the S3 URL parsing error. details: String, }, #[error("error-smokesignal-content-2 File storage operation failed: {operation}")] /// File storage operation failed. StorageFileOperationFailed { /// Description of the failed file operation. operation: String, }, }