aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/errors.rs
blob: 8a208632079ddee1e5ec8a3547330d8e78a442ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use thiserror::Error;

#[derive(Error, Debug)]
pub enum DiceError {
    #[error("解析错误: {0}")]
    ParseError(String),
    #[error("计算错误: {0}")]
    CalculationError(String),
    #[error("无效的骰子表达式: {0}")]
    InvalidExpression(String),
}

impl std::convert::From<DiceError> for pyo3::PyErr {
    fn from(err: DiceError) -> pyo3::PyErr {
        pyo3::PyErr::new::<pyo3::exceptions::PyValueError, _>(err.to_string())
    }
}