conjure_cp_core/representation/
errors.rs1use super::stored::ReprRuleStored;
2#[allow(unused_imports)]
3use super::types::{ReprDeclLevel, ReprDomainLevel};
4use crate::ast::{DeclarationPtr, DomainPtr, Literal};
5use std::fmt::Debug;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
10pub enum ReprInitError {
11 #[error("domain `{}` is not supported by representation `{}`{}", .0, .1, if .2.is_empty() { String::from("") } else { format!(": {}", .2) })]
13 UnsupportedDomain(DomainPtr, &'static str, String),
14 #[error("representation `{}` is not applicable to solver family `{}`", .0, .1.as_str())]
16 WrongSolverFamily(&'static str, crate::settings::SolverFamily),
17 #[error(transparent)]
19 Other(#[from] anyhow::Error),
20}
21
22#[derive(Debug, Error)]
24pub enum ReprInstantiateError {
25 #[error("representation `{}` is already initialised for `{}`", .1, .0.name())]
27 AlreadyExists(DeclarationPtr, &'static str),
28 #[error(
30 "cannot initialise representation `{requested}` for `{declaration}` because it already uses `{existing}` and channelling is disabled"
31 )]
32 ConflictingRepresentation {
33 declaration: DeclarationPtr,
34 existing: &'static str,
35 requested: &'static str,
36 },
37 #[error("declaration `{}` (`{}`) had no domain", .0.name(), .0)]
39 NoDomain(DeclarationPtr),
40 #[error("declaration `{}` (`{}`) had an unsupported kind{}", .0.name(), .0, if .1.is_empty() { String::from("") } else { format!(": {}", .1) })]
42 BadKind(DeclarationPtr, String),
43 #[error("got `{}: {}`, but this representation is for domain `{}`", .0.name(), .0.domain().map(|d| d.to_string()).unwrap_or(String::from("None")), .1)]
45 BadDomain(DeclarationPtr, DomainPtr),
46 #[error(transparent)]
48 Other(#[from] anyhow::Error),
49}
50
51#[derive(Debug, Error)]
53pub enum ReprError {
54 #[error(transparent)]
55 Init(#[from] ReprInitError),
56 #[error(transparent)]
57 Instantiate(#[from] ReprInstantiateError),
58}
59
60#[derive(Debug, Error)]
62pub enum ReferenceReprError {
63 #[error(transparent)]
64 Init(#[from] ReprInitError),
65 #[error(transparent)]
66 Instantiate(#[from] ReprInstantiateError),
67 #[error(transparent)]
68 Select(#[from] ReprSelectError),
69}
70
71impl From<ReprError> for ReferenceReprError {
72 fn from(e: ReprError) -> Self {
73 match e {
74 ReprError::Init(e) => Self::Init(e),
75 ReprError::Instantiate(e) => Self::Instantiate(e),
76 }
77 }
78}
79
80#[derive(Debug, Error)]
81pub enum ReprDownError {
82 #[error("unexpected value `{}`{}", .0, if .1.is_empty() { String::from("") } else { format!(": {}", .1) })]
84 BadValue(Literal, String),
85 #[error(transparent)]
87 Other(#[from] anyhow::Error),
88}
89
90#[derive(Debug, Error)]
91pub enum ReprUpError {
92 #[error("no value found for `{}`", .0.name())]
94 NotFound(DeclarationPtr),
95 #[error("value `{} = {}` is not allowed by domain {}", .0.name(), .1, .2)]
97 BadDomain(DeclarationPtr, Literal, DomainPtr),
98 #[error(transparent)]
100 Other(#[from] anyhow::Error),
101}
102
103#[derive(Debug, Error)]
104pub enum ReprSelectError {
105 #[error("representation `{}` does not exist for variable `{}`", .1, .0.name())]
106 DoesNotExist(DeclarationPtr, &'static str),
107 #[error("this reference already has representation `{}`", .0.name())]
108 AlreadySelected(&'static dyn ReprRuleStored),
109}