1
use crate::ast::ReturnType;
2
use crate::bug;
3
use crate::utils::CombinatoricsError;
4
use thiserror::Error;
5

            
6
/// An error thrown by an operation on domains.
7
#[non_exhaustive]
8
#[derive(Clone, Debug, PartialEq, Eq, Error)]
9
pub enum DomainOpError {
10
    #[error(
11
        "The operation only supports bounded / finite domains, but was given an unbounded input domain."
12
    )]
13
    Unbounded,
14

            
15
    #[error("The operation only supports integer input domains, but got a {0:?} input domain.")]
16
    NotInteger(ReturnType),
17

            
18
    #[error("The operation was given input domains of the wrong type.")]
19
    WrongType,
20

            
21
    #[error("The operation failed as the input domain was not ground")]
22
    NotGround,
23

            
24
    #[error("Could not enumerate the domain as it is too large")]
25
    TooLarge,
26
}
27

            
28
impl From<CombinatoricsError> for DomainOpError {
29
    fn from(value: CombinatoricsError) -> Self {
30
        match value {
31
            CombinatoricsError::Overflow => Self::TooLarge,
32
            CombinatoricsError::NotDefined(msg) => {
33
                bug!("Are we passing the right arguments here? ({})", msg)
34
            }
35
        }
36
    }
37
}