rust_roll/notation/error.rs
1//! Errors from parsing or constructing dice notation.
2
3use std::num::ParseIntError;
4use thiserror::Error;
5
6/// An error from parsing or constructing dice notation.
7#[derive(Debug, Error, PartialEq)]
8#[non_exhaustive]
9pub enum NotationError {
10 /// The input doesn't match the `XdY?Z` notation format.
11 #[error("invalid dice notation; expected something like 2d6+3")]
12 InvalidFormat,
13
14 /// A number in the input couldn't be parsed, usually because it's
15 /// too large for a `u32`.
16 #[error("invalid number: {0}")]
17 InvalidNumber(#[from] ParseIntError),
18
19 /// A value that must be positive was zero. Holds the name of the
20 /// value: `"count"`, `"sides"` or `"divisor"`.
21 #[error("{0} must be greater than zero")]
22 Zero(&'static str),
23
24 /// The operator isn't one of `+`, `-`, `*` or `/`.
25 #[error("invalid operator; expected one of +, -, /, *")]
26 InvalidOperator,
27
28 /// A value exceeded the maximum. Holds the maximum,
29 /// [`MAX_VALUE`](crate::notation::MAX_VALUE).
30 #[error("number too large; maximum is {0}")]
31 NumberTooLarge(u32),
32}