pix_engine/
error.rs

1//! Errors that this crate can return.
2
3use crate::prelude::*;
4use std::{ffi::OsString, io};
5use thiserror::Error;
6
7/// The result type for [`Engine`] operations.
8pub type Result<T> = anyhow::Result<T, anyhow::Error>;
9
10/// The error type for [`Engine`] operations.
11#[non_exhaustive]
12#[derive(Debug, Error)]
13pub enum Error {
14    /// Invalid Texture ID. Texture either doesn't exist or was deleted.
15    #[error("invalid texture id `{0}`")]
16    InvalidTexture(TextureId),
17    /// Invalid Window ID. Window either doesn't exist or was closed.
18    #[error("invalid window id `{0}`")]
19    InvalidWindow(WindowId),
20    /// Hexadecimal [Color] string parsing error. String doesn't match any of `3`, `4`, `6`, or `8`
21    /// digit hexadecimal (radix `16`) values with a leading `#` character.
22    #[error("hexadecimal color string parsing error")]
23    ParseColorError,
24    /// Invalid [Color] slice. Slice length is not in the range `1..=4`.
25    #[error("invalid color slice")]
26    InvalidColorSlice,
27    /// Invalid [Image]. `Image` data does not match it's dimensions based on [`PixelFormat`].
28    #[error(
29        "invalid image {{ width: {width}, height: {height}, size: {size}, format: {format:?} }}"
30    )]
31    InvalidImage {
32        /// `Image` width.
33        width: u32,
34        /// `Image` height.
35        height: u32,
36        /// Size in bytes.
37        size: usize,
38        /// `Image` format.
39        format: PixelFormat,
40    },
41    /// Unsupported [Image] format.
42    #[error("unsupported image format {{ bit_depth: {bit_depth:?}, color_type: {color_type:?} }}")]
43    UnsupportedImageFormat {
44        /// `Image` [png::BitDepth].
45        bit_depth: png::BitDepth,
46        /// `Image` [png::ColorType].
47        color_type: png::ColorType,
48    },
49    /// Unsupported file type.
50    #[error("unsupported file type with extension `{0:?}`")]
51    UnsupportedFileType(Option<OsString>),
52    /// Graphics renderer error.
53    #[error("renderer error: {0}")]
54    Renderer(String),
55    /// I/O errors.
56    #[error(transparent)]
57    Io(#[from] io::Error),
58    /// Other, unspecified errors.
59    #[error(transparent)]
60    Other(#[from] anyhow::Error),
61}