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(
19 "uniform representation conflict for domain `{domain}`: selected `{existing}`, requested `{requested}`"
20 )]
21 UniformConflict {
22 domain: DomainPtr,
23 existing: &'static str,
24 requested: &'static str,
25 },
26 #[error(transparent)]
28 Other(#[from] anyhow::Error),
29}
30
31#[derive(Debug, Error)]
33pub enum ReprInstantiateError {
34 #[error("representation `{}` is already initialised for `{}`", .1, .0.name())]
36 AlreadyExists(DeclarationPtr, &'static str),
37 #[error(
39 "cannot initialise representation `{requested}` for `{declaration}` because it already uses `{existing}` and channelling is disabled"
40 )]
41 ConflictingRepresentation {
42 declaration: DeclarationPtr,
43 existing: &'static str,
44 requested: &'static str,
45 },
46 #[error("declaration `{}` (`{}`) had no domain", .0.name(), .0)]
48 NoDomain(DeclarationPtr),
49 #[error("declaration `{}` (`{}`) had an unsupported kind{}", .0.name(), .0, if .1.is_empty() { String::from("") } else { format!(": {}", .1) })]
51 BadKind(DeclarationPtr, String),
52 #[error("got `{}: {}`, but this representation is for domain `{}`", .0.name(), .0.domain().map(|d| d.to_string()).unwrap_or(String::from("None")), .1)]
54 BadDomain(DeclarationPtr, DomainPtr),
55 #[error(transparent)]
57 Other(#[from] anyhow::Error),
58}
59
60#[derive(Debug, Error)]
62pub enum ReprError {
63 #[error(transparent)]
64 Init(#[from] ReprInitError),
65 #[error(transparent)]
66 Instantiate(#[from] ReprInstantiateError),
67}
68
69#[derive(Debug, Error)]
71pub enum ReferenceReprError {
72 #[error(transparent)]
73 Init(#[from] ReprInitError),
74 #[error(transparent)]
75 Instantiate(#[from] ReprInstantiateError),
76 #[error(transparent)]
77 Select(#[from] ReprSelectError),
78}
79
80impl From<ReprError> for ReferenceReprError {
81 fn from(e: ReprError) -> Self {
82 match e {
83 ReprError::Init(e) => Self::Init(e),
84 ReprError::Instantiate(e) => Self::Instantiate(e),
85 }
86 }
87}
88
89#[derive(Debug, Error)]
90pub enum ReprDownError {
91 #[error("unexpected value `{}`{}", .0, if .1.is_empty() { String::from("") } else { format!(": {}", .1) })]
93 BadValue(Literal, String),
94 #[error(transparent)]
96 Other(#[from] anyhow::Error),
97}
98
99#[derive(Debug, Error)]
100pub enum ReprUpError {
101 #[error("no value found for `{}`", .0.name())]
103 NotFound(DeclarationPtr),
104 #[error("value `{} = {}` is not allowed by domain {}", .0.name(), .1, .2)]
106 BadDomain(DeclarationPtr, Literal, DomainPtr),
107 #[error(transparent)]
109 Other(#[from] anyhow::Error),
110}
111
112#[derive(Debug, Error)]
113pub enum ReprSelectError {
114 #[error("representation `{}` does not exist for variable `{}`", .1, .0.name())]
115 DoesNotExist(DeclarationPtr, &'static str),
116 #[error("this reference already has representation `{}`", .0.name())]
117 AlreadySelected(&'static dyn ReprRuleStored),
118}