The smokesignal.events web application
at main 147 lines 5.9 kB view raw
1use thiserror::Error; 2 3/// Represents errors that can occur during image processing operations. 4/// 5/// These errors typically occur during image validation, resizing, format 6/// conversion, and aspect ratio verification. 7#[derive(Debug, Error)] 8pub(crate) enum ImageError { 9 /// Error when image size exceeds the maximum allowed size. 10 /// 11 /// This error occurs when attempting to process an image that is larger 12 /// than the specified maximum file size limit. 13 #[error("error-smokesignal-image-1 Image size exceeds maximum: {size} bytes > {max} bytes")] 14 SizeExceedsMaximum { 15 /// The actual size of the image in bytes. 16 size: usize, 17 /// The maximum allowed size in bytes. 18 max: usize, 19 }, 20 21 /// Error when image data is invalid or cannot be decoded. 22 /// 23 /// This error occurs when the provided data cannot be decoded as a valid 24 /// image format, typically due to corrupted data or unsupported formats. 25 #[error("error-smokesignal-image-2 Invalid image data: {0}")] 26 InvalidImageData(String), 27 28 /// Error when loading an avatar image fails. 29 /// 30 /// This error occurs when attempting to load image data for avatar 31 /// processing, typically due to invalid format or corrupted data. 32 #[error("error-smokesignal-image-3 Failed to load avatar image: {0}")] 33 AvatarLoadFailed(String), 34 35 /// Error when avatar aspect ratio is not 1:1. 36 /// 37 /// This error occurs when an avatar image doesn't have the required 38 /// square aspect ratio (allowing 5% deviation). 39 #[error("error-smokesignal-image-4 Avatar must have 1:1 aspect ratio: got {width}:{height}")] 40 InvalidAvatarAspectRatio { 41 /// The width of the image in pixels. 42 width: u32, 43 /// The height of the image in pixels. 44 height: u32, 45 }, 46 47 /// Error when encoding an avatar as PNG fails. 48 /// 49 /// This error occurs when the PNG encoding process fails after resizing 50 /// and processing the avatar image. 51 #[error("error-smokesignal-image-5 Failed to encode avatar as PNG: {0}")] 52 AvatarEncodeFailed(String), 53 54 /// Error when loading a banner image fails. 55 /// 56 /// This error occurs when attempting to load image data for banner 57 /// processing, typically due to invalid format or corrupted data. 58 #[error("error-smokesignal-image-6 Failed to load banner image: {0}")] 59 BannerLoadFailed(String), 60 61 /// Error when banner aspect ratio is not 16:9. 62 /// 63 /// This error occurs when a banner image doesn't have the required 64 /// 16:9 aspect ratio (allowing 10% deviation). 65 #[error("error-smokesignal-image-7 Banner must have 16:9 aspect ratio: got {width}:{height}")] 66 InvalidBannerAspectRatio { 67 /// The width of the image in pixels. 68 width: u32, 69 /// The height of the image in pixels. 70 height: u32, 71 }, 72 73 /// Error when encoding a banner as PNG fails. 74 /// 75 /// This error occurs when the PNG encoding process fails after resizing 76 /// and processing the banner image. 77 #[error("error-smokesignal-image-8 Failed to encode banner as PNG: {0}")] 78 BannerEncodeFailed(String), 79 80 /// Error when loading an event header image fails. 81 /// 82 /// This error occurs when attempting to load image data for event header 83 /// processing, typically due to invalid format or corrupted data. 84 #[error("error-smokesignal-image-9 Failed to load event header image: {0}")] 85 EventHeaderLoadFailed(String), 86 87 /// Error when event header aspect ratio is not 3:1. 88 /// 89 /// This error occurs when an event header image doesn't have the required 90 /// 3:1 aspect ratio (allowing 10% deviation). 91 #[error( 92 "error-smokesignal-image-10 Event header must have 3:1 aspect ratio: got {width}:{height}" 93 )] 94 InvalidEventHeaderAspectRatio { 95 /// The width of the image in pixels. 96 width: u32, 97 /// The height of the image in pixels. 98 height: u32, 99 }, 100 101 /// Error when encoding an event header as PNG fails. 102 /// 103 /// This error occurs when the PNG encoding process fails after resizing 104 /// and processing the event header image. 105 #[error("error-smokesignal-image-11 Failed to encode event header as PNG: {0}")] 106 EventHeaderEncodeFailed(String), 107 108 /// Error when loading a thumbnail image fails. 109 /// 110 /// This error occurs when attempting to load image data for thumbnail 111 /// processing, typically due to invalid format or corrupted data. 112 #[error("error-smokesignal-image-12 Failed to load thumbnail image: {0}")] 113 ThumbnailLoadFailed(String), 114 115 /// Error when thumbnail aspect ratio is not 1:1. 116 /// 117 /// This error occurs when a thumbnail image doesn't have the required 118 /// square aspect ratio (allowing 5% deviation). 119 #[error( 120 "error-smokesignal-image-13 Thumbnail must have 1:1 aspect ratio: got {width}:{height}" 121 )] 122 InvalidThumbnailAspectRatio { 123 /// The width of the image in pixels. 124 width: u32, 125 /// The height of the image in pixels. 126 height: u32, 127 }, 128 129 /// Error when thumbnail image is too small. 130 /// 131 /// This error occurs when a thumbnail image is smaller than the minimum 132 /// required size of 512x512 pixels. 133 #[error("error-smokesignal-image-14 Thumbnail must be at least 512x512: got {width}x{height}")] 134 ThumbnailTooSmall { 135 /// The width of the image in pixels. 136 width: u32, 137 /// The height of the image in pixels. 138 height: u32, 139 }, 140 141 /// Error when encoding a thumbnail as PNG fails. 142 /// 143 /// This error occurs when the PNG encoding process fails after resizing 144 /// and processing the thumbnail image. 145 #[error("error-smokesignal-image-15 Failed to encode thumbnail as PNG: {0}")] 146 ThumbnailEncodeFailed(String), 147}