| 1 | use std::{ |
| 2 | error::Error, |
| 3 | ffi::NulError, |
| 4 | fmt::{self, Display, Formatter}, |
| 5 | io, |
| 6 | }; |
| 7 | |
| 8 | /// Enum representing different types of errors that can occur in the canvas. |
| 9 | #[derive (Debug)] |
| 10 | #[non_exhaustive ] |
| 11 | pub enum ErrorKind { |
| 12 | /// An unknown error occurred. |
| 13 | UnknownError, |
| 14 | /// A general error with a custom error message. |
| 15 | GeneralError(String), |
| 16 | /// An error related to image loading (requires "image-loading" feature). |
| 17 | #[cfg (feature = "image-loading" )] |
| 18 | ImageError(::image::ImageError), |
| 19 | /// An I/O error. |
| 20 | IoError(io::Error), |
| 21 | /// An error occurred while parsing a font. |
| 22 | FontParseError, |
| 23 | /// No font was found. |
| 24 | NoFontFound, |
| 25 | /// An error occurred while extracting font information. |
| 26 | FontInfoExtractionError, |
| 27 | /// The font size is too large for the font atlas. |
| 28 | FontSizeTooLargeForAtlas, |
| 29 | /// An error occurred while compiling a shader. |
| 30 | ShaderCompileError(String), |
| 31 | /// An error occurred while linking a shader. |
| 32 | ShaderLinkError(String), |
| 33 | /// An error related to a render target. |
| 34 | RenderTargetError(String), |
| 35 | /// The specified image ID was not found. |
| 36 | ImageIdNotFound, |
| 37 | /// An error occurred while updating an image, as it is out of bounds. |
| 38 | ImageUpdateOutOfBounds, |
| 39 | /// An error occurred while updating an image with a different format. |
| 40 | ImageUpdateWithDifferentFormat, |
| 41 | /// The specified image format is not supported. |
| 42 | UnsupportedImageFormat, |
| 43 | /// The requested operation is not supported (for example screenshot by wgpu renderer). |
| 44 | UnsupportedOperation, |
| 45 | } |
| 46 | |
| 47 | impl Display for ErrorKind { |
| 48 | fn fmt(&self, f: &mut Formatter) -> fmt::Result { |
| 49 | write!(f, "canvas error" ) |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #[cfg (feature = "image-loading" )] |
| 54 | impl From<::image::ImageError> for ErrorKind { |
| 55 | fn from(error: ::image::ImageError) -> Self { |
| 56 | Self::ImageError(error) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | impl From<io::Error> for ErrorKind { |
| 61 | fn from(error: io::Error) -> Self { |
| 62 | Self::IoError(error) |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | impl From<NulError> for ErrorKind { |
| 67 | fn from(error: NulError) -> Self { |
| 68 | Self::GeneralError(error.to_string()) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | impl Error for ErrorKind {} |
| 73 | |