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
    #[error("The attributes provided are conflicting and impossible")]
28
    ConflictingAttrs,
29
}
30

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