wowlab_parsers/parsers/
errors.rs1wowlab_engine_macros::define_error! {
2#[derive(Debug)]
4#[cfg(feature = "dbc")]
5pub struct DbcError {
6 #[source]
7 kind: DbcErrorKind,
8}
9
10#[derive(Debug, thiserror::Error)]
11#[cfg(feature = "dbc")]
12enum DbcErrorKind {
13 #[error("Failed to parse row in '{table}': {source}")]
14 CsvParse {
15 table: String,
16 #[source]
17 source: csv::Error,
18 },
19
20 #[error("IO error reading '{}': {source}", source.path().display())]
21 Io {
22 #[source]
23 source: wowlab_fs::error::Error,
24 },
25}
26}
27
28#[cfg(feature = "dbc")]
29impl DbcError {
30 pub(crate) fn csv_parse(table: String, source: csv::Error) -> Self {
31 Self {
32 kind: DbcErrorKind::CsvParse { table, source },
33 }
34 }
35
36 pub(crate) fn io(source: wowlab_fs::error::Error) -> Self {
37 Self {
38 kind: DbcErrorKind::Io { source },
39 }
40 }
41}
42
43#[cfg(feature = "dbc")]
44impl From<wowlab_fs::error::Error> for DbcError {
45 fn from(source: wowlab_fs::error::Error) -> Self {
46 Self::io(source)
47 }
48}
49
50wowlab_engine_macros::define_error! {
51#[derive(Debug)]
53#[cfg(feature = "dbc")]
54pub struct TransformError {
55 #[source]
56 kind: TransformErrorKind,
57}
58
59#[derive(Debug, thiserror::Error)]
60#[cfg(feature = "dbc")]
61enum TransformErrorKind {
62 #[error("Spell {spell_id} not found in DBC cache")]
63 SpellNotFound { spell_id: i32 },
64
65 #[error("Spec {spec_id} not found in DBC cache")]
66 SpecNotFound { spec_id: i32 },
67
68 #[error("Class {class_id} not found in DBC cache")]
69 ClassNotFound { class_id: i32 },
70
71 #[error("Global color {color_id} not found in DBC cache")]
72 GlobalColorNotFound { color_id: i32 },
73
74 #[error("Global string {string_id} not found in DBC cache")]
75 GlobalStringNotFound { string_id: i32 },
76
77 #[error("Loadout for spec {spec_id} not found")]
78 LoadoutNotFound { spec_id: i32 },
79
80 #[error("Trait tree {tree_id} not found in DBC cache")]
81 TraitTreeNotFound { tree_id: i32 },
82
83 #[error("Item {item_id} not found in DBC cache")]
84 ItemNotFound { item_id: i32 },
85
86 #[cfg(feature = "dbc")]
87 #[error(transparent)]
88 Dbc(DbcError),
89}
90}
91
92#[cfg(feature = "dbc")]
93impl TransformError {
94 pub(crate) const fn spell_not_found(spell_id: i32) -> Self {
95 Self {
96 kind: TransformErrorKind::SpellNotFound { spell_id },
97 }
98 }
99
100 pub(crate) const fn spec_not_found(spec_id: i32) -> Self {
101 Self {
102 kind: TransformErrorKind::SpecNotFound { spec_id },
103 }
104 }
105
106 pub(crate) const fn class_not_found(class_id: i32) -> Self {
107 Self {
108 kind: TransformErrorKind::ClassNotFound { class_id },
109 }
110 }
111
112 pub(crate) const fn global_color_not_found(color_id: i32) -> Self {
113 Self {
114 kind: TransformErrorKind::GlobalColorNotFound { color_id },
115 }
116 }
117
118 pub(crate) const fn global_string_not_found(string_id: i32) -> Self {
119 Self {
120 kind: TransformErrorKind::GlobalStringNotFound { string_id },
121 }
122 }
123
124 pub(crate) const fn loadout_not_found(spec_id: i32) -> Self {
125 Self {
126 kind: TransformErrorKind::LoadoutNotFound { spec_id },
127 }
128 }
129
130 pub(crate) const fn trait_tree_not_found(tree_id: i32) -> Self {
131 Self {
132 kind: TransformErrorKind::TraitTreeNotFound { tree_id },
133 }
134 }
135
136 pub(crate) const fn item_not_found(item_id: i32) -> Self {
137 Self {
138 kind: TransformErrorKind::ItemNotFound { item_id },
139 }
140 }
141}
142
143#[cfg(feature = "dbc")]
144impl From<DbcError> for TransformError {
145 fn from(error: DbcError) -> Self {
146 Self {
147 kind: TransformErrorKind::Dbc(error),
148 }
149 }
150}