Skip to main content

ifc_style/
error.rs

1//! Typed failures while projecting or authoring presentation data.
2
3use ifc_model::EntityId;
4use thiserror::Error;
5
6/// A malformed, unresolved, or unsupported presentation contract.
7#[derive(Debug, Clone, PartialEq, Error)]
8#[non_exhaustive]
9pub enum StyleError {
10    /// An entity id was looked up but the model does not contain it.
11    #[error("entity {id} does not exist")]
12    UnknownEntity {
13        /// The id that resolved to nothing.
14        id: EntityId,
15    },
16    /// An entity was read as one IFC type but is actually another.
17    #[error("expected {expected}, found {actual} at {id}")]
18    WrongEntityType {
19        /// The entity that was read.
20        id: EntityId,
21        /// The IFC type the caller expected.
22        expected: &'static str,
23        /// The IFC type actually declared.
24        actual: String,
25    },
26    /// The active schema does not declare the requested entity type.
27    #[error("schema {schema} does not declare {entity}")]
28    UnsupportedEntity {
29        /// The schema's name.
30        schema: String,
31        /// The entity type name that is undeclared.
32        entity: &'static str,
33    },
34    /// A mandatory attribute was absent, so the value cannot be inferred.
35    #[error("{entity} {id} is missing required attribute {attribute}")]
36    MissingAttribute {
37        /// The entity's IFC type.
38        entity: String,
39        /// The entity that was read.
40        id: EntityId,
41        /// Schema name of the attribute.
42        attribute: &'static str,
43    },
44    /// An attribute was present but held the wrong kind of value.
45    #[error("{entity} {id} has invalid {attribute}: {value}")]
46    InvalidValue {
47        /// The entity's IFC type.
48        entity: String,
49        /// The entity that was read.
50        id: EntityId,
51        /// Schema name of the attribute.
52        attribute: &'static str,
53        /// Debug-formatted offending value.
54        value: String,
55    },
56    /// The active schema declares the entity but not the requested attribute slot.
57    #[error("entity {entity} in schema {schema} has no attribute {attribute}")]
58    UnsupportedAttribute {
59        /// The schema's name.
60        schema: String,
61        /// The entity type name.
62        entity: &'static str,
63        /// The attribute name that is undeclared.
64        attribute: &'static str,
65    },
66    /// A reference attribute pointed at an entity id the model does not contain.
67    #[error("reference {target} from {source_id} does not resolve")]
68    DanglingReference {
69        /// The entity holding the dangling reference.
70        source_id: EntityId,
71        /// The id that resolved to nothing.
72        target: EntityId,
73    },
74    /// A reference resolved, but the target is not the IFC type (or select
75    /// member) the referencing slot requires.
76    #[error("reference {target} has type {actual}, expected {expected}")]
77    ReferenceType {
78        /// The entity that was read.
79        target: EntityId,
80        /// The IFC type (or select) the slot requires.
81        expected: &'static str,
82        /// The IFC type actually declared.
83        actual: String,
84    },
85    /// An authoring helper was given a value it cannot encode for the target attribute.
86    #[error("cannot author {entity}.{attribute}: {value}")]
87    AuthoringInvalid {
88        /// The IFC entity type being authored.
89        entity: &'static str,
90        /// The attribute being set.
91        attribute: &'static str,
92        /// Debug-formatted offending value.
93        value: String,
94    },
95    /// A normalized-ratio or bounded measure fell outside its required range.
96    #[error("{entity} {id}.{attribute} is outside [{minimum}, {maximum}]: {value}")]
97    OutOfRange {
98        /// The measure's IFC type, e.g. `"IfcNormalisedRatioMeasure"`.
99        entity: &'static str,
100        /// The entity that was read.
101        id: EntityId,
102        /// Schema name of the attribute.
103        attribute: &'static str,
104        /// The out-of-range value.
105        value: f64,
106        /// The inclusive lower bound.
107        minimum: f64,
108        /// The inclusive upper bound.
109        maximum: f64,
110    },
111    /// More than one `IfcStyledItem` directly assigned styles to the same
112    /// representation item; cascade resolution refuses to guess a winner.
113    #[error("representation item {item} has {count} direct styled-item assignments")]
114    AmbiguousStyleAssignment {
115        /// The representation item with conflicting direct assignments.
116        item: EntityId,
117        /// The number of conflicting `IfcStyledItem`s found.
118        count: usize,
119    },
120}
121
122/// The result type returned by this crate's projection and authoring operations.
123pub type StyleResult<T> = Result<T, StyleError>;