tex_packer_core/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum TexPackerError {
5    #[error("I/O error: {0}")]
6    Io(#[from] std::io::Error),
7
8    #[error("Image error: {0}")]
9    Image(#[from] image::ImageError),
10
11    #[error("Invalid input: {0}")]
12    InvalidInput(String),
13
14    #[error("Invalid configuration: {0}")]
15    InvalidConfig(String),
16
17    #[error(
18        "Texture '{key}' ({width}x{height}) exceeds maximum atlas dimensions ({max_width}x{max_height})"
19    )]
20    TextureTooLarge {
21        key: String,
22        width: u32,
23        height: u32,
24        max_width: u32,
25        max_height: u32,
26    },
27
28    #[error(
29        "Out of space: unable to fit texture '{key}' ({width}x{height}) into atlas (tried {pages_attempted} page(s))"
30    )]
31    OutOfSpace {
32        key: String,
33        width: u32,
34        height: u32,
35        pages_attempted: usize,
36    },
37
38    #[error(
39        "Out of space: unable to fit remaining textures into atlas (placed {placed}/{total} textures)"
40    )]
41    OutOfSpaceGeneric { placed: usize, total: usize },
42
43    #[error("Nothing to pack: input list is empty")]
44    Empty,
45
46    #[error("Encoding error: {0}")]
47    Encode(String),
48
49    #[error("Invalid dimensions: width and height must be greater than 0 (got {width}x{height})")]
50    InvalidDimensions { width: u32, height: u32 },
51
52    #[error(
53        "Invalid padding configuration: border_padding ({border}) + texture_padding ({texture}) + texture_extrusion ({extrusion}) exceeds available space"
54    )]
55    InvalidPadding {
56        border: u32,
57        texture: u32,
58        extrusion: u32,
59    },
60}
61
62pub type Result<T> = std::result::Result<T, TexPackerError>;