The smokesignal.events web application
at main 73 lines 3.3 kB view raw
1use thiserror::Error; 2 3/// Represents errors that can occur during application configuration. 4/// 5/// These errors typically happen during application startup when loading 6/// and validating configuration from environment variables and files. 7#[derive(Debug, Error)] 8pub enum ConfigError { 9 /// Error when a required environment variable is not set. 10 /// 11 /// This error occurs when the application starts up and a required 12 /// environment variable is missing from the execution environment. 13 #[error("error-smokesignal-config-1 {0} must be set")] 14 EnvVarRequired(String), 15 16 /// Error when no valid signing keys are found. 17 /// 18 /// This error occurs when the OAuth client credentials key is empty 19 /// or cannot be identified as a valid key. 20 #[error("error-smokesignal-config-4 OAuth client credentials key must be a valid key")] 21 EmptySigningKeys, 22 23 /// Error when the PORT environment variable cannot be parsed. 24 /// 25 /// This error occurs when the PORT environment variable contains a value 26 /// that cannot be parsed as a valid u16 integer. 27 #[error("error-smokesignal-config-7 Parsing PORT into u16 failed: {0:?}")] 28 PortParsingFailed(std::num::ParseIntError), 29 30 /// Error when the HTTP_COOKIE_KEY cannot be decoded. 31 /// 32 /// This error occurs when the HTTP_COOKIE_KEY environment variable 33 /// contains a value that is not valid base64-encoded data. 34 #[error("error-smokesignal-config-8 Unable to base64 decode HTTP_COOKIE_KEY: {0:?}")] 35 CookieKeyDecodeFailed(base64::DecodeSliceError), 36 37 /// Error when the decoded HTTP_COOKIE_KEY cannot be processed. 38 /// 39 /// This error occurs when the decoded HTTP_COOKIE_KEY has an invalid 40 /// format or length that prevents it from being used. 41 #[error("error-smokesignal-config-9 Unable to process decoded HTTP_COOKIE_KEY")] 42 CookieKeyProcessFailed, 43 44 /// Error when version information is not available. 45 /// 46 /// This error occurs when neither GIT_HASH nor CARGO_PKG_VERSION 47 /// environment variables are set, preventing version identification. 48 #[error("error-smokesignal-config-10 One of GIT_HASH or CARGO_PKG_VERSION must be set")] 49 VersionNotSet, 50 51 /// Error when a DNS nameserver IP cannot be parsed. 52 /// 53 /// This error occurs when the DNS_NAMESERVERS environment variable contains 54 /// an IP address that cannot be parsed as a valid IpAddr. 55 #[error("error-smokesignal-config-12 Unable to parse nameserver IP '{0}': {1}")] 56 NameserverParsingFailed(String, std::net::AddrParseError), 57 58 /// Error when the EMAIL_SECRET_KEY cannot be decoded. 59 /// 60 /// This error occurs when the EMAIL_SECRET_KEY environment variable 61 /// contains a value that is not valid hex-encoded data. 62 #[error("error-smokesignal-config-21 Unable to hex decode EMAIL_SECRET_KEY: {0:?}")] 63 EmailSecretKeyDecodeFailed(hex::FromHexError), 64 65 /// Error when the EMAIL_SECRET_KEY is too short. 66 /// 67 /// This error occurs when the decoded EMAIL_SECRET_KEY is less than 68 /// 32 bytes (256 bits), which is the minimum required for security. 69 #[error( 70 "error-smokesignal-config-22 EMAIL_SECRET_KEY must be at least 32 bytes, got {0} bytes" 71 )] 72 EmailSecretKeyTooShort(usize), 73}