wow_sharedmedia/error.rs
1use std::path::PathBuf;
2
3/// Core error type for the wow-sharedmedia library.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 // === Addon Directory Errors ===
7 /// The requested addon directory does not exist.
8 #[error("Addon directory not found: {0}")]
9 AddonNotFound(PathBuf),
10
11 // === Data Errors ===
12 /// Failed to parse the addon's `data.lua` file into structured data.
13 #[error("Failed to parse data.lua: {0}")]
14 DataLuaParse(String),
15
16 // === Entry Errors ===
17 /// No entry exists for the provided UUID.
18 #[error("Entry not found: {0}")]
19 EntryNotFound(uuid::Uuid),
20
21 /// An entry with the same media type and key already exists.
22 #[error("Duplicate key '{key}' for type '{type}' (existing ID: {existing_id})")]
23 DuplicateKey {
24 /// Asset type involved in the collision.
25 r#type: crate::MediaType,
26 /// Duplicate display key.
27 key: String,
28 /// UUID of the existing conflicting entry.
29 existing_id: uuid::Uuid,
30 },
31
32 // === Import Errors ===
33 /// The input file extension is not accepted for the target media type.
34 #[error("Unsupported file format for type '{target_type}': {extension}")]
35 UnsupportedFormat {
36 /// Target asset type.
37 target_type: crate::MediaType,
38 /// Rejected file extension.
39 extension: String,
40 },
41
42 /// The image file could not be parsed or validated.
43 #[error("Invalid image file: {0}")]
44 InvalidImage(String),
45
46 /// The image has invalid zero or negative-equivalent dimensions.
47 #[error("Image dimensions must be positive, got {width}x{height}")]
48 InvalidDimensions {
49 /// Reported width.
50 width: u32,
51 /// Reported height.
52 height: u32,
53 },
54
55 /// The image exceeds the supported maximum dimension.
56 #[error("Image too large (max {max}x{max}): {actual}x{actual}")]
57 ImageTooLarge {
58 /// Maximum allowed dimension.
59 max: u32,
60 /// Actual dimension encountered.
61 actual: u32,
62 },
63
64 /// The font file could not be parsed or validated.
65 #[error("Invalid font file: {0}")]
66 InvalidFont(String),
67
68 /// Locale configuration is invalid for the requested operation.
69 #[error("Invalid locale configuration: {0}")]
70 InvalidLocale(String),
71
72 /// The audio file could not be parsed or validated.
73 #[error("Invalid audio file: {0}")]
74 InvalidAudio(String),
75
76 /// The file exceeds the per-type size limit.
77 #[error("File too large: {actual} bytes (max {max} bytes)")]
78 FileTooLarge {
79 /// File path checked.
80 path: PathBuf,
81 /// Actual file size in bytes.
82 actual: u64,
83 /// Maximum accepted file size in bytes.
84 max: u64,
85 },
86
87 // === Conversion Errors ===
88 /// Image transcoding or serialization failed.
89 #[error("Failed to convert image: {0}")]
90 ImageConversion(String),
91
92 /// Audio transcoding or serialization failed.
93 #[error("Failed to convert audio: {0}")]
94 AudioConversion(String),
95
96 // === I/O Errors ===
97 /// Filesystem access failed.
98 #[error("I/O error on {path}: {source}")]
99 Io {
100 /// Original I/O error.
101 #[source]
102 source: std::io::Error,
103 /// Path involved in the failed operation.
104 path: PathBuf,
105 },
106
107 // === Lua Errors ===
108 /// Interaction with the embedded Lua runtime failed.
109 #[error("Lua error: {0}")]
110 Lua(#[from] mlua::Error),
111}