use std::fmt;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum LensError {
#[error("vertex not found: {0}")]
VertexNotFound(String),
#[error("edge not found: {src} -> {tgt}")]
EdgeNotFound {
src: String,
tgt: String,
},
#[error("field not found: {0}")]
FieldNotFound(String),
#[error("cannot coerce from {from} to {to}")]
IncompatibleCoercion {
from: String,
to: String,
},
#[error(
"composition failed: target schema of first lens does not match source schema of second"
)]
CompositionMismatch,
#[error("restrict error: {0}")]
Restrict(#[from] panproto_inst::RestrictError),
#[error("complement mismatch: {detail}")]
ComplementMismatch {
detail: String,
},
}
#[derive(Debug)]
#[non_exhaustive]
pub enum LawViolation {
GetPut {
detail: String,
},
PutGet {
detail: String,
},
Error(LensError),
}
impl fmt::Display for LawViolation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::GetPut { detail } => write!(f, "GetPut law violated: {detail}"),
Self::PutGet { detail } => write!(f, "PutGet law violated: {detail}"),
Self::Error(e) => write!(f, "error during law check: {e}"),
}
}
}
impl std::error::Error for LawViolation {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Error(e) => Some(e),
_ => None,
}
}
}