Skip to main content

wowlab_engine_gamedata/
error.rs

1//! Errors produced while reading required resolved game data.
2
3use wowlab_types::sim::SpellIdx;
4
5wowlab_engine_macros::define_error! {
6/// A required resolved game-data coordinate was absent.
7#[derive(Debug)]
8pub struct GameDataError {
9    #[source]
10    kind: GameDataErrorKind,
11}
12
13#[derive(Debug, thiserror::Error)]
14enum GameDataErrorKind {
15    #[error("missing game data for spell {spell_id} (field: {field})")]
16    MissingSpellField {
17        spell_id: u32,
18        field: &'static str,
19    },
20    #[error(
21        "missing {field} for spell {spell_id} effect {effect_index} (required coefficient)"
22    )]
23    MissingEffectField {
24        spell_id: u32,
25        effect_index: u8,
26        field: &'static str,
27    },
28    #[error("spell {spell_id} has no valid resolved empower stage timings")]
29    InvalidEmpowerTimings { spell_id: u32 },
30    #[error("spell {spell_id} has no resolved empower rank {rank}")]
31    MissingEmpowerRank { spell_id: u32, rank: u8 },
32    #[error("spell {spell_id} has no valid resolved empower stage count")]
33    InvalidEmpowerRankCount { spell_id: u32 },
34}
35}
36
37impl GameDataError {
38    pub(crate) const fn missing_spell_field(spell_id: SpellIdx, field: &'static str) -> Self {
39        Self {
40            kind: GameDataErrorKind::MissingSpellField {
41                spell_id: spell_id.as_u32(),
42                field,
43            },
44        }
45    }
46
47    pub(crate) const fn missing_effect_field(
48        spell_id: SpellIdx,
49        effect_index: u8,
50        field: &'static str,
51    ) -> Self {
52        Self {
53            kind: GameDataErrorKind::MissingEffectField {
54                spell_id: spell_id.as_u32(),
55                effect_index,
56                field,
57            },
58        }
59    }
60
61    pub(crate) const fn invalid_empower_timings(spell_id: SpellIdx) -> Self {
62        Self {
63            kind: GameDataErrorKind::InvalidEmpowerTimings {
64                spell_id: spell_id.as_u32(),
65            },
66        }
67    }
68
69    pub(crate) const fn missing_empower_rank(spell_id: SpellIdx, rank: u8) -> Self {
70        Self {
71            kind: GameDataErrorKind::MissingEmpowerRank {
72                spell_id: spell_id.as_u32(),
73                rank,
74            },
75        }
76    }
77
78    pub(crate) const fn invalid_empower_rank_count(spell_id: SpellIdx) -> Self {
79        Self {
80            kind: GameDataErrorKind::InvalidEmpowerRankCount {
81                spell_id: spell_id.as_u32(),
82            },
83        }
84    }
85}