The smokesignal.events web application
at main 185 lines 7.3 kB view raw
1use thiserror::Error; 2 3/// Represents errors that can occur during email operations. 4/// 5/// These errors typically occur during email template rendering, 6/// email confirmation token generation/verification, and SMTP sending. 7#[derive(Debug, Error)] 8pub enum EmailError { 9 /// Error when the HMAC secret key is invalid. 10 /// 11 /// This error occurs when attempting to create an HMAC instance with 12 /// an invalid key format or length. 13 #[error("error-smokesignal-email-1 Invalid HMAC key: {0}")] 14 InvalidHmacKey(String), 15 16 /// Error when the confirmation token format is invalid. 17 /// 18 /// This error occurs when attempting to parse a confirmation token 19 /// that doesn't match the expected format (token.time_bucket.signature). 20 #[error("error-smokesignal-email-2 Invalid confirmation token format")] 21 InvalidTokenFormat, 22 23 /// Error when the time bucket in a confirmation token cannot be parsed. 24 /// 25 /// This error occurs when the time bucket component of a confirmation 26 /// token is not a valid integer. 27 #[error("error-smokesignal-email-3 Invalid time bucket in confirmation token")] 28 InvalidTimeBucket, 29 30 /// Error when the confirmation token signature is invalid or expired. 31 /// 32 /// This error occurs when the HMAC signature of a confirmation token 33 /// doesn't match the expected value, or the token has expired (older 34 /// than the previous 10-minute time bucket). 35 #[error("error-smokesignal-email-4 Invalid or expired confirmation token signature")] 36 InvalidOrExpiredSignature, 37 38 /// Error when a template file contains invalid UTF-8. 39 /// 40 /// This error occurs when loading an email template file that contains 41 /// invalid UTF-8 byte sequences. 42 #[error("error-smokesignal-email-5 Invalid UTF-8 in template {template}: {details}")] 43 InvalidUtf8InTemplate { 44 /// The name of the template file. 45 template: String, 46 /// Details about the UTF-8 error. 47 details: String, 48 }, 49 50 /// Error when adding a template to the template engine fails. 51 /// 52 /// This error occurs when the template engine rejects a template, 53 /// typically due to syntax errors or invalid template directives. 54 #[error("error-smokesignal-email-6 Failed to add template {template}: {details}")] 55 TemplateAddFailed { 56 /// The name of the template file. 57 template: String, 58 /// Details about why adding the template failed. 59 details: String, 60 }, 61 62 /// Error when retrieving a text template fails. 63 /// 64 /// This error occurs when attempting to get a template that doesn't 65 /// exist or cannot be loaded from the template engine. 66 #[error("error-smokesignal-email-7 Failed to get text template {template}: {details}")] 67 TextTemplateGetFailed { 68 /// The path to the template. 69 template: String, 70 /// Details about the retrieval failure. 71 details: String, 72 }, 73 74 /// Error when rendering a text template fails. 75 /// 76 /// This error occurs when template rendering fails, typically due to 77 /// missing variables or invalid template syntax. 78 #[error("error-smokesignal-email-8 Failed to render text template {template}: {details}")] 79 TextTemplateRenderFailed { 80 /// The path to the template. 81 template: String, 82 /// Details about the rendering failure. 83 details: String, 84 }, 85 86 /// Error when retrieving an HTML template fails. 87 /// 88 /// This error occurs when attempting to get an HTML template that doesn't 89 /// exist or cannot be loaded from the template engine. 90 #[error("error-smokesignal-email-9 Failed to get HTML template {template}: {details}")] 91 HtmlTemplateGetFailed { 92 /// The path to the template. 93 template: String, 94 /// Details about the retrieval failure. 95 details: String, 96 }, 97 98 /// Error when rendering an HTML template fails. 99 /// 100 /// This error occurs when HTML template rendering fails, typically due to 101 /// missing variables or invalid template syntax. 102 #[error("error-smokesignal-email-10 Failed to render HTML template {template}: {details}")] 103 HtmlTemplateRenderFailed { 104 /// The path to the template. 105 template: String, 106 /// Details about the rendering failure. 107 details: String, 108 }, 109 110 /// Error when CSS inlining fails. 111 /// 112 /// This error occurs when the CSS inlining process fails, typically 113 /// due to invalid CSS syntax or malformed HTML. 114 #[error("error-smokesignal-email-11 Failed to inline CSS in template {template}: {details}")] 115 CssInlineFailed { 116 /// The path to the template. 117 template: String, 118 /// Details about the CSS inlining failure. 119 details: String, 120 }, 121 122 /// Error when HTML minification fails. 123 /// 124 /// This error occurs when the HTML minification process fails, 125 /// typically due to malformed HTML structure. 126 #[error("error-smokesignal-email-12 Failed to minify HTML in template {template}: {details}")] 127 HtmlMinifyFailed { 128 /// The path to the template. 129 template: String, 130 /// Details about the minification failure. 131 details: String, 132 }, 133 134 /// Error when parsing SMTP credentials fails. 135 /// 136 /// This error occurs when the SMTP username cannot be parsed into 137 /// valid SMTP credentials format. 138 #[error("error-smokesignal-email-13 Failed to parse SMTP credentials: {0}")] 139 SmtpCredentialsParseFailed(String), 140 141 /// Error when the "from" email address is invalid. 142 /// 143 /// This error occurs when the SMTP_FROM address cannot be parsed 144 /// as a valid email address. 145 #[error("error-smokesignal-email-14 Invalid from email address: {0}")] 146 InvalidFromAddress(String), 147 148 /// Error when a recipient email address is invalid. 149 /// 150 /// This error occurs when a recipient's email address cannot be parsed 151 /// as a valid email address. 152 #[error("error-smokesignal-email-15 Invalid recipient email address {address}: {details}")] 153 InvalidRecipientAddress { 154 /// The invalid email address. 155 address: String, 156 /// Details about why the address is invalid. 157 details: String, 158 }, 159 160 /// Error when building an email message fails. 161 /// 162 /// This error occurs when the email builder fails to construct a valid 163 /// email message, typically due to missing required fields. 164 #[error("error-smokesignal-email-16 Failed to build email message: {0}")] 165 EmailBuildFailed(String), 166 167 /// Error when sending an email fails. 168 /// 169 /// This error occurs when the SMTP transport fails to send the email, 170 /// typically due to network issues or SMTP server errors. 171 #[error("error-smokesignal-email-17 Failed to send email: {0}")] 172 EmailSendFailed(String), 173 174 /// Error when an attachment content type is invalid. 175 /// 176 /// This error occurs when parsing a content type string for an email 177 /// attachment fails. 178 #[error("error-smokesignal-email-18 Invalid attachment content type {content_type}: {details}")] 179 InvalidAttachmentContentType { 180 /// The invalid content type string. 181 content_type: String, 182 /// Details about the parsing failure. 183 details: String, 184 }, 185}