gpl_math/
error.rs

1//! Error types
2
3use {
4    num_derive::FromPrimitive,
5    gemachain_program::{decode_error::DecodeError, program_error::ProgramError},
6    thiserror::Error,
7};
8
9/// Errors that may be returned by the Math program.
10#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
11pub enum MathError {
12    /// Calculation overflowed the destination number
13    #[error("Calculation overflowed the destination number")]
14    Overflow,
15    /// Calculation underflowed the destination number
16    #[error("Calculation underflowed the destination number")]
17    Underflow,
18}
19impl From<MathError> for ProgramError {
20    fn from(e: MathError) -> Self {
21        ProgramError::Custom(e as u32)
22    }
23}
24impl<T> DecodeError<T> for MathError {
25    fn type_of() -> &'static str {
26        "Math Error"
27    }
28}