Skip to main content

ifc_cost/mutation/
error.rs

1//! Typed refusal reasons for cost authoring.
2
3use ifc_model::EntityId;
4use ifc_schema::SchemaVersion;
5use thiserror::Error;
6
7/// Why a bounded IFC4 cost draft was refused before staging.
8#[derive(Debug, Clone, PartialEq, Eq, Error)]
9#[non_exhaustive]
10pub enum CostAuthoringError {
11    /// A scalar, enum-dependent field, aggregate, or identifier was invalid.
12    #[error("invalid {entity}.{attribute}: {reason}")]
13    InvalidValue {
14        /// IFC entity type being authored.
15        entity: &'static str,
16        /// IFC attribute being validated.
17        attribute: &'static str,
18        /// Stable human-readable refusal reason.
19        reason: String,
20    },
21    /// A draft referenced an entity absent from the projected transaction state.
22    #[error("{entity}.{attribute} references missing {target}")]
23    MissingReference {
24        /// IFC entity type being authored.
25        entity: &'static str,
26        /// IFC reference attribute being validated.
27        attribute: &'static str,
28        /// Missing entity identifier.
29        target: EntityId,
30    },
31    /// A referenced entity had the wrong exact type for this bounded contract.
32    #[error("{entity}.{attribute} references {target} of type {actual}; expected {expected}")]
33    WrongReferenceType {
34        /// IFC entity type being authored.
35        entity: &'static str,
36        /// IFC reference attribute being validated.
37        attribute: &'static str,
38        /// Referenced entity identifier.
39        target: EntityId,
40        /// Actual projected entity type.
41        actual: String,
42        /// Required exact IFC4 entity type.
43        expected: &'static str,
44    },
45    /// A cost item was already nested under another parent.
46    #[error("cost item {child} already has parent {existing_parent}")]
47    MultipleParents {
48        /// Child item being attached.
49        child: EntityId,
50        /// Existing parent in the projected transaction state.
51        existing_parent: EntityId,
52    },
53    /// A proposed cost-item edge would create a self-reference or cycle.
54    #[error("cost item nesting would create a cycle through {item}")]
55    NestingCycle {
56        /// Item at which cycle validation refused the draft.
57        item: EntityId,
58    },
59    /// The model's header declares several schemas; release-bound
60    /// authoring binds to exactly one.
61    #[error("the header declares {schemas} schemas; authoring binds to exactly one")]
62    MultipleSchemas {
63        /// Number of `FILE_SCHEMA` declarations.
64        schemas: usize,
65    },
66    /// The model's header declares one schema with no bundled table, so no
67    /// layout can be trusted.
68    #[error("the header declares {schema}, which has no bundled table")]
69    UnsupportedSchema {
70        /// The `FILE_SCHEMA` token as written.
71        schema: String,
72    },
73    /// The model's release does not declare this entity, such as
74    /// `IfcQuantityNumber` (IFC4X3 only) in an IFC2X3 or IFC4 model.
75    #[error("{entity} is not an entity of {schema:?}")]
76    EntityNotInSchema {
77        /// IFC entity type being authored.
78        entity: &'static str,
79        /// The release the model declares.
80        schema: SchemaVersion,
81    },
82    /// A draft supplied a value for an attribute the model's release does
83    /// not declare, such as a `Formula` for an IFC2X3 quantity. It is
84    /// refused rather than dropped.
85    #[error("cannot author {entity}.{attribute}: not defined by {schema:?}")]
86    AuthoringNotInSchema {
87        /// IFC entity type being authored.
88        entity: &'static str,
89        /// The attribute.
90        attribute: &'static str,
91        /// The release the model declares.
92        schema: SchemaVersion,
93    },
94    /// A draft supplied a value the release's declaration cannot hold, such
95    /// as a date string where IFC2X3 declares an `IfcDateTimeSelect` record
96    /// (`IfcCostSchedule.SubmittedOn`), or a token its enumeration lacks.
97    #[error("cannot author {entity}.{attribute}: {schema:?} declares it {declared}")]
98    AuthoringValueType {
99        /// IFC entity type being authored.
100        entity: &'static str,
101        /// The attribute, by its IFC4 name.
102        attribute: &'static str,
103        /// The type the release declares.
104        declared: &'static str,
105        /// The release the model declares.
106        schema: SchemaVersion,
107    },
108    /// The release requires an attribute the call leaves unset, such as the
109    /// IFC2X3 `IfcRoot.OwnerHistory` (#202). It is refused rather than
110    /// written as `$`; the `*_with_owner_history` writers take the
111    /// `IfcOwnerHistory` IFC2X3 needs.
112    #[error("cannot author {entity}: {schema:?} requires {attribute}")]
113    AuthoringRequired {
114        /// IFC entity type being authored.
115        entity: &'static str,
116        /// The attribute, by the release's own name.
117        attribute: &'static str,
118        /// The release the model declares.
119        schema: SchemaVersion,
120    },
121}
122
123/// Result returned by bounded cost authoring helpers.
124pub type CostAuthoringResult<T> = Result<T, CostAuthoringError>;