i18n+filtering fork - fluent-templates v2
at main 5.6 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-config-1 {0} must be set")] 14 EnvVarRequired(String), 15 16 /// Error when the signing keys file cannot be read. 17 /// 18 /// This error occurs when the application fails to read the file 19 /// containing signing keys, typically due to file system permissions 20 /// or missing file issues. 21 #[error("error-config-2 Unable to read signing keys file: {0:?}")] 22 ReadSigningKeysFailed(std::io::Error), 23 24 /// Error when the signing keys file cannot be parsed. 25 /// 26 /// This error occurs when the signing keys file contains malformed JSON 27 /// that cannot be properly deserialized. 28 #[error("error-config-3 Unable to parse signing keys file: {0:?}")] 29 ParseSigningKeysFailed(serde_json::Error), 30 31 /// Error when no valid signing keys are found. 32 /// 33 /// This error occurs when the signing keys file does not contain any 34 /// valid keys that the application can use for signing operations. 35 #[error("error-config-4 Signing keys must contain at least one valid key")] 36 EmptySigningKeys, 37 38 /// Error when the destination key is invalid. 39 /// 40 /// This error occurs when the DESTINATION_KEY environment variable 41 /// does not reference a valid key in the SIGNING_KEYS file. 42 #[error("error-config-5 DESTINATION_KEY must be a valid key in the SIGNING_KEYS file")] 43 InvalidDestinationKey, 44 45 /// Error when no valid OAuth active keys are found. 46 /// 47 /// This error occurs when the configuration does not include any 48 /// valid keys that can be used for OAuth operations. 49 #[error("error-config-6 OAuth active keys must contain at least one valid key")] 50 EmptyOAuthActiveKeys, 51 52 /// Error when no valid invitation active keys are found. 53 /// 54 /// This error occurs when the configuration does not include any 55 /// valid keys that can be used for invitation operations. 56 #[error("error-config-7 Invitation active keys must contain at least one valid key")] 57 EmptyInvitationActiveKeys, 58 59 /// Error when the PORT environment variable cannot be parsed. 60 /// 61 /// This error occurs when the PORT environment variable contains a value 62 /// that cannot be parsed as a valid u16 integer. 63 #[error("error-config-8 Parsing PORT into u16 failed: {0:?}")] 64 PortParsingFailed(std::num::ParseIntError), 65 66 /// Error when the HTTP_COOKIE_KEY cannot be decoded. 67 /// 68 /// This error occurs when the HTTP_COOKIE_KEY environment variable 69 /// contains a value that is not valid base64-encoded data. 70 #[error("error-config-9 Unable to base64 decode HTTP_COOKIE_KEY: {0:?}")] 71 CookieKeyDecodeFailed(base64::DecodeSliceError), 72 73 /// Error when the decoded HTTP_COOKIE_KEY cannot be processed. 74 /// 75 /// This error occurs when the decoded HTTP_COOKIE_KEY has an invalid 76 /// format or length that prevents it from being used. 77 #[error("error-config-10 Unable to process decoded HTTP_COOKIE_KEY")] 78 CookieKeyProcessFailed, 79 80 /// Error when version information is not available. 81 /// 82 /// This error occurs when neither GIT_HASH nor CARGO_PKG_VERSION 83 /// environment variables are set, preventing version identification. 84 #[error("error-config-11 One of GIT_HASH or CARGO_PKG_VERSION must be set")] 85 VersionNotSet, 86 87 /// Error when a referenced signing key is not found. 88 /// 89 /// This error occurs when attempting to use a signing key that 90 /// does not exist in the loaded signing keys configuration. 91 #[error("error-config-12 Signing key not found")] 92 SigningKeyNotFound, 93 94 /// Error when a DNS nameserver IP cannot be parsed. 95 /// 96 /// This error occurs when the DNS_NAMESERVERS environment variable contains 97 /// an IP address that cannot be parsed as a valid IpAddr. 98 #[error("error-config-13 Unable to parse nameserver IP '{0}': {1}")] 99 NameserverParsingFailed(String, std::net::AddrParseError), 100 101 /// Error when the signing keys file is not found. 102 /// 103 /// This error occurs when the file specified in the SIGNING_KEYS environment 104 /// variable does not exist on the file system. 105 #[error("error-config-14 Signing keys file not found: {0}")] 106 SigningKeysFileNotFound(String), 107 108 /// Error when the signing keys file is empty. 109 /// 110 /// This error occurs when the file specified in the SIGNING_KEYS environment 111 /// variable exists but contains no data. 112 #[error("error-config-15 Signing keys file is empty")] 113 EmptySigningKeysFile, 114 115 /// Error when the JWKS structure doesn't contain any keys. 116 /// 117 /// This error occurs when the signing keys file contains a valid JWKS structure, 118 /// but the 'keys' array is empty. 119 #[error("error-config-16 No keys found in JWKS")] 120 MissingKeysInJWKS, 121 122 /// Error when signing keys fail validation. 123 /// 124 /// This error occurs when the signing keys file contains keys 125 /// that fail validation checks (such as having invalid format). 126 #[error("error-config-17 Signing keys validation failed: {0:?}")] 127 SigningKeysValidationFailed(Vec<String>), 128}