Skip to main content

manabrew_engine/ability/
illegal_ability_exception.rs

1//! IllegalAbilityException — error type for invalid abilities.
2//!
3//! Mirrors Java's `IllegalAbilityException.java`.
4
5use std::fmt;
6
7/// Error raised when an ability cannot be resolved or is malformed.
8#[derive(Debug, Clone)]
9pub struct IllegalAbilityException {
10    pub message: String,
11}
12
13impl IllegalAbilityException {
14    /// Create from a descriptive message.
15    pub fn new(message: impl Into<String>) -> Self {
16        Self {
17            message: message.into(),
18        }
19    }
20
21    /// Create from a spell ability description and effect name.
22    pub fn with_effect(sa_desc: &str, effect_name: &str) -> Self {
23        Self {
24            message: format!("{} (effect {})", sa_desc, effect_name),
25        }
26    }
27}
28
29impl fmt::Display for IllegalAbilityException {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        write!(f, "IllegalAbilityException: {}", self.message)
32    }
33}
34
35impl std::error::Error for IllegalAbilityException {}