1use ifc_model::{EntityId, ModelError};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8#[non_exhaustive]
9pub enum StepError {
10 #[error("not a STEP physical file: {0}")]
12 NotStep(String),
13
14 #[error("syntax error at byte {offset}: {detail}")]
16 Syntax {
17 offset: usize,
19 detail: String,
21 },
22
23 #[error("entity record without an id at byte {offset}")]
25 MissingEntityId {
26 offset: usize,
28 },
29
30 #[error("entity #{entity} slot {slot} contains a non-finite REAL")]
32 NonFiniteReal {
33 entity: EntityId,
35 slot: usize,
37 },
38
39 #[error("io error: {0}")]
41 Io(String),
42}
43
44impl From<openbim_step::StepError> for StepError {
45 fn from(error: openbim_step::StepError) -> Self {
46 if error.is_not_step() {
47 Self::NotStep(error.detail().to_owned())
48 } else {
49 Self::Syntax {
50 offset: error.span().start,
51 detail: error.detail().to_owned(),
52 }
53 }
54 }
55}
56
57impl From<StepError> for ModelError {
58 fn from(error: StepError) -> Self {
59 match error {
60 StepError::NotStep(detail) => ModelError::WrongFormat {
61 expected: "STEP",
62 detail,
63 },
64 StepError::Syntax { offset, detail } => ModelError::Syntax { offset, detail },
65 StepError::MissingEntityId { offset } => ModelError::Syntax {
66 offset,
67 detail: "entity record without an id".into(),
68 },
69 StepError::NonFiniteReal { entity, slot } => ModelError::Write(format!(
70 "entity #{entity} slot {slot} contains a non-finite REAL"
71 )),
72 StepError::Io(message) => ModelError::Io(message),
73 }
74 }
75}