ifc_model/error.rs
1//! Why a model operation failed.
2
3use crate::value::EntityId;
4use thiserror::Error;
5
6/// Errors from reading, writing, or querying a model.
7///
8/// Codec-specific detail is carried as a message rather than a nested error
9/// type: this crate must not depend on any codec, so it cannot name their
10/// error types.
11#[derive(Debug, Error)]
12pub enum ModelError {
13 /// Underlying I/O failure.
14 #[error("io error: {0}")]
15 Io(String),
16
17 /// The bytes are not this format at all.
18 #[error("not a {expected} file: {detail}")]
19 WrongFormat {
20 /// Format the codec expected.
21 expected: &'static str,
22 /// What was seen instead.
23 detail: String,
24 },
25
26 /// Syntax error at a known location.
27 #[error("syntax error at byte {offset}: {detail}")]
28 Syntax {
29 /// Byte offset into the source.
30 offset: usize,
31 /// What went wrong.
32 detail: String,
33 },
34
35 /// An entity referenced an id that does not exist.
36 #[error("entity {from} references missing entity {to}")]
37 DanglingReference {
38 /// The referring entity.
39 from: EntityId,
40 /// The missing target.
41 to: EntityId,
42 },
43
44 /// The same id was defined twice.
45 #[error("duplicate entity id {0}")]
46 DuplicateId(EntityId),
47
48 /// Serialization failed.
49 #[error("write error: {0}")]
50 Write(String),
51}
52
53/// Convenience alias.
54pub type ModelResult<T> = Result<T, ModelError>;