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(
15 "Invalid dimensions for '{key}': width and height must be greater than 0 (got {width}x{height})"
16 )]
17 InvalidItemDimensions {
18 key: String,
19 width: u32,
20 height: u32,
21 },
22
23 #[error("No packable inputs remain after preprocessing: {keys:?}")]
24 NoPackableInputs { keys: Vec<String> },
25
26 #[error("Invalid configuration: {0}")]
27 InvalidConfig(String),
28
29 #[error("Atlas invariant violation at {context}: {reason}")]
30 InvariantViolation { context: String, reason: String },
31
32 #[error("Invalid atlas document: {reason}")]
33 InvalidDocument { reason: String },
34
35 #[error(
36 "Texture '{key}' ({width}x{height}) exceeds maximum atlas dimensions ({max_width}x{max_height})"
37 )]
38 TextureTooLarge {
39 key: String,
40 width: u32,
41 height: u32,
42 max_width: u32,
43 max_height: u32,
44 },
45
46 #[error(
47 "Out of space: unable to fit texture '{key}' ({width}x{height}) into atlas (tried {pages_attempted} page(s))"
48 )]
49 OutOfSpace {
50 key: String,
51 width: u32,
52 height: u32,
53 pages_attempted: usize,
54 },
55
56 #[error(
57 "Out of space: unable to fit remaining textures into atlas (placed {placed}/{total} textures)"
58 )]
59 OutOfSpaceGeneric { placed: usize, total: usize },
60
61 #[error("Nothing to pack: input list is empty")]
62 Empty,
63
64 #[error("Encoding error: {0}")]
65 Encode(String),
66
67 #[error("Invalid dimensions: width and height must be greater than 0 (got {width}x{height})")]
68 InvalidDimensions { width: u32, height: u32 },
69
70 #[error("Duplicate runtime key: '{key}'")]
71 DuplicateKey { key: String },
72
73 #[error(
74 "Invalid padding configuration: border_padding ({border}) + texture_padding ({texture}) + texture_extrusion ({extrusion}) exceeds available space"
75 )]
76 InvalidPadding {
77 border: u32,
78 texture: u32,
79 extrusion: u32,
80 },
81}
82
83pub type Result<T> = std::result::Result<T, TexPackerError>;