p2panda_rs/document/
error.rs1use thiserror::Error;
6
7use crate::operation::OperationId;
8
9#[derive(Error, Debug)]
11pub enum DocumentBuilderError {
12 #[error("Schema must be set")]
14 SchemaMustBeSet,
15
16 #[error("operation {0} cannot be connected to the document graph")]
18 InvalidOperationLink(OperationId),
19
20 #[error("multiple CREATE operations found when building operation graph")]
22 MultipleCreateOperations,
23
24 #[error(transparent)]
26 DocumentViewError(#[from] DocumentViewError),
27
28 #[error(transparent)]
30 GraphSortingError(#[from] crate::graph::error::GraphError),
31
32 #[error(transparent)]
34 DocumentReducerError(#[from] DocumentReducerError),
35}
36
37#[derive(Error, Debug)]
39pub enum DocumentError {
40 #[error("operation {0} does not update the documents current view")]
42 PreviousDoesNotMatch(OperationId),
43
44 #[error("Operation {0} does not match the documents schema")]
46 InvalidSchemaId(OperationId),
47
48 #[error("Cannot perform a commit on a deleted document")]
50 UpdateOnDeleted,
51
52 #[error("Cannot update an existing document with a create operation")]
54 CommitCreate,
55
56 #[error(transparent)]
58 DocumentViewError(#[from] DocumentViewError),
59
60 #[error(transparent)]
62 GraphSortingError(#[from] crate::graph::error::GraphError),
63}
64
65#[derive(Error, Debug)]
67pub enum DocumentReducerError {
68 #[error("The first operation of a document must be a CREATE")]
70 FirstOperationNotCreate,
71
72 #[error(transparent)]
74 DocumentError(#[from] DocumentError),
75}
76
77#[derive(Error, Debug)]
79#[allow(missing_copy_implementations)]
80pub enum DocumentViewError {
81 #[error("operation must be instantiated from a CREATE operation")]
83 NotCreateOperation,
84
85 #[error("operation passed to update() must be UPDATE or DELETE")]
87 NotUpdateOrDeleteOperation,
88}
89
90#[derive(Error, Debug)]
92pub enum DocumentViewIdError {
93 #[error("expected sorted operation ids in document view id")]
95 UnsortedOperationIds,
96
97 #[error("expected one or more operation ids")]
99 ZeroOperationIds,
100
101 #[error(transparent)]
103 InvalidOperationId(#[from] crate::operation::error::OperationIdError),
104}
105
106#[derive(Error, Debug)]
108pub enum DocumentIdError {
109 #[error(transparent)]
111 OperationIdError(#[from] crate::operation::error::OperationIdError),
112}