1use crate::EntityId;
8use thiserror::Error;
9
10pub type Result<T> = std::result::Result<T, ParseError>;
12
13#[derive(Error, Debug)]
15pub enum ParseError {
16 #[error("Invalid IFC format: {0}")]
18 InvalidFormat(String),
19
20 #[error("Invalid header: {0}")]
22 InvalidHeader(String),
23
24 #[error("Failed to parse entity {0}: {1}")]
26 EntityParse(EntityId, String),
27
28 #[error("Entity {0} not found")]
30 EntityNotFound(EntityId),
31
32 #[error("Invalid entity reference at {entity}: attribute {attribute}")]
34 InvalidReference { entity: EntityId, attribute: usize },
35
36 #[error(
38 "Type mismatch at entity {entity} attribute {attribute}: expected {expected}, got {actual}"
39 )]
40 TypeMismatch {
41 entity: EntityId,
42 attribute: usize,
43 expected: String,
44 actual: String,
45 },
46
47 #[error("Missing required attribute {attribute} on entity {entity}")]
49 MissingAttribute { entity: EntityId, attribute: usize },
50
51 #[error("Unsupported schema version: {0}")]
53 UnsupportedSchema(String),
54
55 #[error("Geometry error for entity {entity}: {message}")]
57 Geometry { entity: EntityId, message: String },
58
59 #[error("IO error: {0}")]
61 Io(#[from] std::io::Error),
62
63 #[error("{0}")]
65 Other(String),
66}
67
68impl ParseError {
69 pub fn format(msg: impl Into<String>) -> Self {
71 ParseError::InvalidFormat(msg.into())
72 }
73
74 pub fn entity_parse(id: EntityId, msg: impl Into<String>) -> Self {
76 ParseError::EntityParse(id, msg.into())
77 }
78
79 pub fn geometry(entity: EntityId, msg: impl Into<String>) -> Self {
81 ParseError::Geometry {
82 entity,
83 message: msg.into(),
84 }
85 }
86
87 pub fn other(msg: impl Into<String>) -> Self {
89 ParseError::Other(msg.into())
90 }
91}