Skip to main content

ifc_cost/
error.rs

1//! Why a cost lookup failed.
2
3use thiserror::Error;
4
5/// Failures specific to interpreting cost data.
6#[derive(Debug, Error)]
7#[non_exhaustive]
8pub enum CostError {
9    /// An entity was expected to be a cost entity but is not.
10    #[error("entity #{id} is {actual}, not {expected}")]
11    WrongType {
12        /// The entity id.
13        id: u64,
14        /// The type it actually has.
15        actual: String,
16        /// The type that was expected.
17        expected: &'static str,
18    },
19
20    /// The model's header declares one schema the cost readers are not
21    /// verified against (anything but IFC2X3, IFC4 and IFC4X3), so no
22    /// attribute position can be trusted. Never read as another release.
23    #[error("the header declares {schema}, which the cost readers are not verified against")]
24    UnsupportedSchema {
25        /// The `FILE_SCHEMA` token as written, or the release identifier.
26        schema: String,
27    },
28
29    /// The model's header declares several schemas; a reader binds to
30    /// exactly one release.
31    #[error("the header declares {schemas} schemas; a reader binds to exactly one")]
32    MultipleSchemas {
33        /// Number of `FILE_SCHEMA` declarations.
34        schemas: usize,
35    },
36
37    /// A referenced cost value or quantity does not exist.
38    #[error("cost item #{from} references missing entity #{to}")]
39    MissingReference {
40        /// The referring cost item.
41        from: u64,
42        /// The missing target.
43        to: u64,
44    },
45}