Skip to main content

ifc_control/
error.rs

1//! Typed failures for bounded IFC control semantics.
2
3use ifc_model::EntityId;
4use thiserror::Error;
5
6/// Control projection or authoring failure.
7///
8/// Only the variants this crate can actually raise are declared. A
9/// variant that no code path constructs is a promise the crate does
10/// not keep, and callers write dead match arms for it.
11#[derive(Debug, Clone, PartialEq, Error)]
12#[non_exhaustive]
13pub enum ControlError {
14    /// Entity kind differs from the requested projection.
15    #[error("expected {expected}, found {actual}")]
16    WrongEntityType {
17        /// Expected IFC entity.
18        expected: &'static str,
19        /// Actual IFC entity.
20        actual: String,
21    },
22    /// Required positional attribute is absent or null.
23    #[error("{entity} {id} is missing {attribute}")]
24    MissingAttribute {
25        /// Entity kind.
26        entity: &'static str,
27        /// Entity identifier.
28        id: EntityId,
29        /// Attribute name.
30        attribute: &'static str,
31    },
32    /// Requested entity is absent.
33    #[error("entity {id} does not exist")]
34    UnknownEntity {
35        /// Missing identifier.
36        id: EntityId,
37    },
38    /// Draft value is invalid before staging, including an `OwnerHistory`
39    /// that is not an `IfcOwnerHistory`.
40    #[error("cannot author {entity}.{attribute}: {value}")]
41    AuthoringInvalid {
42        /// Entity kind.
43        entity: &'static str,
44        /// Attribute or rule.
45        attribute: &'static str,
46        /// Rejected value.
47        value: String,
48    },
49    /// The relating control of an assignment is not one this crate owns.
50    ///
51    /// Cost schedules, cost items and work controls are `IfcControl`s
52    /// too; their own crates write assignments to them.
53    #[error("{id} is {actual}, not a control ifc-control owns")]
54    ForeignControl {
55        /// The offered relating control.
56        id: EntityId,
57        /// Its type name.
58        actual: String,
59    },
60    /// The schema in use does not declare this entity.
61    ///
62    /// Authoring an entity the schema omits is a caller error, not a
63    /// silently-skipped attribute.
64    #[error("{schema} does not declare {entity}")]
65    UnsupportedEntity {
66        /// Schema name.
67        schema: String,
68        /// Entity that is not declared.
69        entity: &'static str,
70    },
71    /// The model's header declares several schemas; release-bound
72    /// authoring binds to exactly one.
73    #[error("the header declares {schemas} schemas; authoring binds to exactly one")]
74    MultipleSchemas {
75        /// Number of `FILE_SCHEMA` declarations.
76        schemas: usize,
77    },
78    /// The model's header declares one schema with no bundled table, so no
79    /// layout can be trusted.
80    #[error("the header declares {schema}, which has no bundled table")]
81    UnsupportedSchema {
82        /// The `FILE_SCHEMA` token as written.
83        schema: String,
84    },
85    /// A draft supplied a value for an attribute the release does not
86    /// declare, such as a `PredefinedType` for an IFC2X3 `IfcPermit`. It is
87    /// refused rather than dropped.
88    #[error("cannot author {entity}.{attribute}: not declared by {schema}")]
89    AuthoringNotInSchema {
90        /// Entity kind.
91        entity: &'static str,
92        /// The attribute, by its IFC4 name.
93        attribute: &'static str,
94        /// Schema name.
95        schema: String,
96    },
97    /// A draft supplied a value the release's declaration of the attribute
98    /// cannot hold.
99    #[error("cannot author {entity}.{attribute}: {schema} declares it {declared}")]
100    AuthoringValueType {
101        /// Entity kind.
102        entity: &'static str,
103        /// The attribute, by its IFC4 name.
104        attribute: &'static str,
105        /// The type the release declares.
106        declared: String,
107        /// Schema name.
108        schema: String,
109    },
110    /// The release requires an attribute the call leaves unset, such as the
111    /// IFC2X3 `IfcRoot.OwnerHistory` (#198, #202) or `IfcPermit.PermitID`.
112    /// It is refused rather than written as `$`; the `*_with_owner_history`
113    /// writers take the `IfcOwnerHistory` IFC2X3 needs.
114    #[error("cannot author {entity}: {schema} requires {attribute}")]
115    AuthoringRequired {
116        /// Entity kind.
117        entity: &'static str,
118        /// The attribute, by the release's own name.
119        attribute: String,
120        /// Schema name.
121        schema: String,
122    },
123}
124
125/// Result alias for control operations.
126pub type ControlResult<T> = Result<T, ControlError>;