argumentation_weighted/error.rs
1//! Crate error types.
2
3use thiserror::Error;
4
5/// Errors that can occur in the `argumentation-weighted` crate.
6#[derive(Debug, Error)]
7pub enum Error {
8 /// An attack weight was non-finite (NaN or infinity) or negative.
9 /// Dunne 2011 requires non-negative finite weights.
10 #[error("invalid attack weight {weight}: weights must be non-negative finite f64")]
11 InvalidWeight {
12 /// The weight that failed validation.
13 weight: f64,
14 },
15
16 /// A budget value was non-finite or negative.
17 #[error("invalid budget {budget}: budgets must be non-negative finite f64")]
18 InvalidBudget {
19 /// The budget that failed validation.
20 budget: f64,
21 },
22
23 /// A weighted framework exceeded the Dunne 2011 subset-enumeration
24 /// attack-count limit. The exact semantics enumerate the power set
25 /// of attacks, so the limit caps memory+time at 2^limit subsets.
26 #[error("too many attacks for exact Dunne 2011 enumeration: {attacks} attacks exceed the limit of {limit}")]
27 TooManyAttacks {
28 /// The number of attacks in the offending framework.
29 attacks: usize,
30 /// The current enumeration limit.
31 limit: usize,
32 },
33
34 /// An error from the underlying Dung layer (e.g., framework too
35 /// large for subset enumeration).
36 #[error("dung error: {0}")]
37 Dung(#[from] argumentation::Error),
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn too_many_attacks_error_carries_count_and_limit() {
46 let err = Error::TooManyAttacks { attacks: 30, limit: 24 };
47 let msg = format!("{}", err);
48 assert!(msg.contains("30"));
49 assert!(msg.contains("24"));
50 }
51}