use ifc_model::EntityId;
use ifc_schema::SchemaVersion;
use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Error)]
#[non_exhaustive]
pub enum ConstraintError {
#[error("expected {expected}, found {actual}")]
WrongEntityType {
expected: &'static str,
actual: String,
},
#[error("{entity} {id} is missing {attribute}")]
MissingAttribute {
entity: &'static str,
id: EntityId,
attribute: &'static str,
},
#[error("{entity} {id}.{attribute} is invalid: {value}")]
InvalidValue {
entity: &'static str,
id: EntityId,
attribute: &'static str,
value: String,
},
#[error("entity {id} does not exist")]
UnknownEntity {
id: EntityId,
},
#[error("{entity} {id}.{attribute} reference {target} does not resolve")]
DanglingReference {
entity: &'static str,
id: EntityId,
attribute: &'static str,
target: EntityId,
},
#[error("{entity} {id}.{attribute} target {target} has {actual}, expected {expected}")]
ReferenceType {
entity: &'static str,
id: EntityId,
attribute: &'static str,
target: EntityId,
expected: &'static str,
actual: String,
},
#[error("{entity} {id} violates {rule}: {detail}")]
Semantic {
entity: &'static str,
id: EntityId,
rule: &'static str,
detail: String,
},
#[error("cannot author {entity}.{attribute}: {value}")]
AuthoringInvalid {
entity: &'static str,
attribute: &'static str,
value: String,
},
#[error("authoring target {target} has {actual}, expected {expected}")]
AuthoringReferenceType {
target: EntityId,
expected: &'static str,
actual: String,
},
#[error("the header declares {schemas} schemas; authoring binds to exactly one")]
MultipleSchemas {
schemas: usize,
},
#[error("the header declares {schema}, which has no bundled table")]
UnsupportedSchema {
schema: String,
},
#[error("cannot author {entity}: {schema:?} requires {attribute}")]
AuthoringRequired {
entity: &'static str,
attribute: &'static str,
schema: SchemaVersion,
},
}
pub type ConstraintResult<T> = Result<T, ConstraintError>;