Skip to main content

dotloom_document/
error.rs

1use thiserror::Error;
2
3use crate::{ConstraintId, EntityId, GroupId, LayerId};
4
5/// Document-level errors (invariant violations, invalid edits, limits).
6#[derive(Debug, Clone, PartialEq, Error)]
7#[non_exhaustive]
8pub enum DocError {
9    /// Malformed type identifier.
10    #[error("invalid type id `{0}`")]
11    InvalidTypeId(String),
12    /// The same ID appears twice.
13    #[error("duplicate id {0}")]
14    DuplicateId(String),
15    /// An entity does not exist.
16    #[error("unknown entity {0}")]
17    UnknownEntity(EntityId),
18    /// A constraint does not exist.
19    #[error("unknown constraint {0}")]
20    UnknownConstraint(ConstraintId),
21    /// A layer does not exist.
22    #[error("unknown layer {0}")]
23    UnknownLayer(LayerId),
24    /// A group does not exist.
25    #[error("unknown group {0}")]
26    UnknownGroup(GroupId),
27    /// A reference points to a missing target.
28    #[error("{from} references missing {target}")]
29    BrokenReference {
30        /// Referencing object.
31        from: String,
32        /// Missing target.
33        target: String,
34    },
35    /// An anchor name is not provided by the referenced entity.
36    #[error("entity {entity} has no anchor `{anchor}`")]
37    MissingAnchor {
38        /// Entity.
39        entity: EntityId,
40        /// Anchor name.
41        anchor: String,
42    },
43    /// A parameter name is not provided by the referenced entity.
44    #[error("entity {entity} has no numeric parameter `{param}`")]
45    MissingParam {
46        /// Entity.
47        entity: EntityId,
48        /// Parameter name.
49        param: String,
50    },
51    /// Group nesting forms a cycle.
52    #[error("group cycle through {0}")]
53    GroupCycle(GroupId),
54    /// An entity or group belongs to more than one group.
55    #[error("{0} is a member of more than one group")]
56    MultipleParents(String),
57    /// The entity order list is not a permutation of the entities.
58    #[error("entity order is inconsistent: {0}")]
59    BadOrder(String),
60    /// Geometry is invalid.
61    #[error("invalid geometry for {entity}: {reason}")]
62    InvalidGeometry {
63        /// Entity.
64        entity: EntityId,
65        /// Reason.
66        reason: String,
67    },
68    /// A value is invalid.
69    #[error("invalid value: {0}")]
70    InvalidValue(String),
71    /// A configured limit was exceeded.
72    #[error("limit exceeded: {0}")]
73    LimitExceeded(String),
74    /// The document schema is newer than this library supports.
75    #[error("document schema {found} is newer than supported schema {supported}; upgrade Dotloom to open it")]
76    FutureSchema {
77        /// Schema found in the file.
78        found: u32,
79        /// Newest supported schema.
80        supported: u32,
81    },
82    /// The document schema is older than any supported migration.
83    #[error("document schema {0} is not supported")]
84    UnsupportedSchema(u32),
85    /// JSON (de)serialization error.
86    #[error("malformed document: {0}")]
87    Malformed(String),
88}