Skip to main content

ifc_occurrence/
error.rs

1//! Why an occurrence was refused.
2
3use ifc_model::EntityId;
4use ifc_schema::SchemaVersion;
5
6/// Why an occurrence was refused.
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum OccurrenceError {
10    /// `GlobalId` did not parse as a 22-character IFC GUID.
11    MalformedGuid {
12        /// The offending value.
13        value: String,
14    },
15    /// The token is not a member of this class's own enum.
16    UnknownPredefinedType {
17        /// STEP class.
18        entity: &'static str,
19        /// The offending token.
20        token: String,
21    },
22    /// The class has no `PredefinedType` attribute at all.
23    NoPredefinedType {
24        /// STEP class.
25        entity: &'static str,
26    },
27    /// `USERDEFINED` was given without an `ObjectType` naming it.
28    UserDefinedWithoutObjectType {
29        /// STEP class.
30        entity: &'static str,
31    },
32    /// The occurrence was typed by a class the bound release does not pair
33    /// with it.
34    WrongTypeClass {
35        /// STEP class of the occurrence.
36        entity: &'static str,
37        /// The only class the release permits, such as `IFCDOORTYPE` for an
38        /// IFC4 `IfcDoor` or `IFCDOORSTYLE` for an IFC2X3 one.
39        expected: &'static str,
40        /// What the referenced entity actually is.
41        found: String,
42    },
43    /// The class permits no type at all, but one was supplied.
44    TypingNotPermitted {
45        /// STEP class.
46        entity: &'static str,
47    },
48    /// The bound release pairs no type class with this occurrence class,
49    /// such as an IFC2X3 `IfcStair`, whose `IfcStairType` IFC2X3 does not
50    /// declare, but one was supplied (#214).
51    TypeClassNotInSchema {
52        /// STEP class.
53        entity: &'static str,
54        /// The release the model declares.
55        schema: SchemaVersion,
56    },
57    /// The typed-by reference does not resolve in the model.
58    UnresolvedType {
59        /// The dangling id.
60        id: EntityId,
61    },
62    /// An enumeration token outside the enumeration the bound release
63    /// declares for the attribute, such as a `ShapeType` or `BarRole`.
64    UnknownToken {
65        /// STEP class.
66        entity: &'static str,
67        /// The attribute.
68        attribute: &'static str,
69        /// The offending token.
70        token: String,
71    },
72    /// A measure the attribute's type does not admit: a non-positive or
73    /// non-finite `IfcPositiveLengthMeasure`, or a non-finite
74    /// `IfcAreaMeasure`.
75    InvalidMeasure {
76        /// STEP class.
77        entity: &'static str,
78        /// The attribute.
79        attribute: &'static str,
80        /// The offending value, as written by `{:?}`.
81        value: String,
82    },
83    /// The model's header declares several schemas; authoring binds to
84    /// exactly one release.
85    MultipleSchemas {
86        /// Number of `FILE_SCHEMA` declarations.
87        schemas: usize,
88    },
89    /// The model's header declares one schema with no bundled table, so no
90    /// layout can be trusted.
91    UnsupportedSchema {
92        /// The `FILE_SCHEMA` token as written.
93        schema: String,
94    },
95    /// The model's release does not declare the class, or declares it
96    /// abstract, such as `IfcBorehole` (IFC4X3 only) in an IFC4 model.
97    EntityNotInSchema {
98        /// STEP class.
99        entity: &'static str,
100        /// The release the model declares.
101        schema: SchemaVersion,
102    },
103    /// A value for an attribute the model's release does not declare on the
104    /// class. It is refused rather than dropped.
105    AuthoringNotInSchema {
106        /// STEP class.
107        entity: &'static str,
108        /// The attribute.
109        attribute: &'static str,
110        /// The release the model declares.
111        schema: SchemaVersion,
112    },
113    /// The model's release requires an attribute the call leaves unset,
114    /// such as the IFC2X3 `IfcRoot.OwnerHistory`.
115    AuthoringRequired {
116        /// STEP class.
117        entity: &'static str,
118        /// The required attribute, as the release names it.
119        attribute: &'static str,
120        /// The release the model declares.
121        schema: SchemaVersion,
122    },
123    /// The owner-history reference resolves neither in the model nor on the
124    /// transaction.
125    UnresolvedOwnerHistory {
126        /// The dangling id.
127        id: EntityId,
128    },
129    /// The owner-history reference is not an `IfcOwnerHistory`.
130    NotAnOwnerHistory {
131        /// The referenced id.
132        id: EntityId,
133        /// What the referenced entity actually is.
134        found: String,
135    },
136}
137
138impl std::fmt::Display for OccurrenceError {
139    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
140        match self {
141            Self::MalformedGuid { value } => write!(f, "malformed GlobalId {value:?}"),
142            Self::UnknownPredefinedType { entity, token } => {
143                write!(f, "{entity}.PredefinedType: {token} is not a member")
144            }
145            Self::NoPredefinedType { entity } => write!(f, "{entity} has no PredefinedType"),
146            Self::UserDefinedWithoutObjectType { entity } => {
147                write!(f, "{entity}: USERDEFINED needs an ObjectType")
148            }
149            Self::WrongTypeClass {
150                entity,
151                expected,
152                found,
153            } => write!(f, "{entity} is typed by {expected}, not {found}"),
154            Self::TypingNotPermitted { entity } => write!(f, "{entity} takes no type"),
155            Self::TypeClassNotInSchema { entity, schema } => {
156                write!(f, "{schema:?} pairs no type class with {entity}")
157            }
158            Self::UnresolvedType { id } => write!(f, "type #{} does not exist", id.0),
159            Self::UnknownToken {
160                entity,
161                attribute,
162                token,
163            } => write!(f, "{entity}.{attribute}: {token} is not a member"),
164            Self::InvalidMeasure {
165                entity,
166                attribute,
167                value,
168            } => write!(f, "{entity}.{attribute}: {value} is not admitted"),
169            Self::MultipleSchemas { schemas } => write!(
170                f,
171                "the header declares {schemas} schemas; authoring binds to exactly one"
172            ),
173            Self::UnsupportedSchema { schema } => {
174                write!(
175                    f,
176                    "the header declares {schema}, which has no bundled table"
177                )
178            }
179            Self::EntityNotInSchema { entity, schema } => {
180                write!(f, "{entity} is not an instantiable entity of {schema:?}")
181            }
182            Self::AuthoringNotInSchema {
183                entity,
184                attribute,
185                schema,
186            } => write!(
187                f,
188                "cannot author {entity}.{attribute}: not defined by {schema:?}"
189            ),
190            Self::AuthoringRequired {
191                entity,
192                attribute,
193                schema,
194            } => write!(f, "cannot author {entity}: {schema:?} requires {attribute}"),
195            Self::UnresolvedOwnerHistory { id } => {
196                write!(f, "owner history #{} does not exist", id.0)
197            }
198            Self::NotAnOwnerHistory { id, found } => {
199                write!(f, "#{} is a {found}, not an IfcOwnerHistory", id.0)
200            }
201        }
202    }
203}
204
205impl std::error::Error for OccurrenceError {}
206
207/// Result alias for this crate.
208pub type OccurrenceResult<T> = Result<T, OccurrenceError>;