p2panda_rs/api/
errors.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3use crate::document::DocumentId;
4use crate::entry::error::DecodeEntryError;
5use crate::identity::PublicKey;
6use crate::operation::error::ValidateOperationError;
7use crate::operation::OperationId;
8use crate::schema::SchemaId;
9use crate::storage_provider::error::{EntryStorageError, LogStorageError, OperationStorageError};
10
11/// Error type used in the validation module.
12#[derive(thiserror::Error, Debug)]
13pub enum ValidationError {
14    /// The claimed sequence number didn't match the expected.
15    #[error("Entry's claimed seq num of {0} does not match expected seq num of {1} for given public key and log")]
16    SeqNumDoesNotMatch(u64, u64),
17
18    /// The expected skiplink entry wasn't found in the store.
19    #[error("Expected skiplink entry not found in store: public key {0}, log id {1}, seq num {2}")]
20    ExpectedSkiplinkNotFound(String, u64, u64),
21
22    /// The claimed log id didn't match the expected for a given public key and document id.
23    #[error(
24        "Entry's claimed log id of {0} does not match existing log id of {1} for given public key and document id"
25    )]
26    LogIdDoesNotMatchExisting(u64, u64),
27
28    /// The expected log for given public key and document id not found.
29    #[error("Expected log not found in store for: public key {0}, document id {1}")]
30    ExpectedDocumentLogNotFound(PublicKey, DocumentId),
31
32    /// Claimed log id is already in use.
33    #[error("Entry's claimed log id of {0} is already in use for given public key")]
34    LogIdDuplicate(u64),
35
36    /// Entry with seq num 1 contained a skiplink.
37    #[error("Entry with seq num 1 can not have skiplink")]
38    FirstEntryWithSkiplink,
39
40    /// Claimed schema does not match the documents expected schema.
41    #[error("Operation {0} claims incorrect schema {1} for document with schema {2}")]
42    InvalidClaimedSchema(OperationId, SchemaId, SchemaId),
43
44    /// This document is deleted.
45    #[error("Document is deleted")]
46    DocumentDeleted,
47
48    /// Max u64 sequence number reached.
49    #[error("Max sequence number reached")]
50    MaxSeqNum,
51
52    /// Max u64 log id reached.
53    #[error("Max log id reached")]
54    MaxLogId,
55
56    /// An operation in the `previous` field was not found in the store.
57    #[error("Previous operation {0} not found in store")]
58    PreviousOperationNotFound(OperationId),
59
60    /// A document view id was provided which contained operations from different documents.
61    #[error("Operations in passed document view id originate from different documents")]
62    InvalidDocumentViewId,
63
64    /// Error coming from the log store.
65    #[error(transparent)]
66    LogStoreError(#[from] LogStorageError),
67
68    /// Error coming from the entry store.
69    #[error(transparent)]
70    EntryStoreError(#[from] EntryStorageError),
71
72    /// Error coming from the operation store.
73    #[error(transparent)]
74    OperationStoreError(#[from] OperationStorageError),
75}
76
77/// Error type used in the domain module.
78#[derive(thiserror::Error, Debug)]
79pub enum DomainError {
80    /// The maximum u64 sequence number has been reached for the public key and log id combination.
81    #[error("Max sequence number reached for public key {0} log {1}")]
82    MaxSeqNumReached(String, u64),
83
84    /// Tried to update or delete a deleted document.
85    #[error("You are trying to update or delete a document which has been deleted")]
86    DeletedDocument,
87
88    /// Expected log id not found when calculating next args.
89    #[error("Expected log id {0} not found when calculating next args")]
90    ExpectedLogIdNotFound(u64),
91
92    /// Validation errors.
93    #[error(transparent)]
94    ValidationError(#[from] ValidationError),
95
96    /// Error coming from the log store.
97    #[error(transparent)]
98    LogStoreError(#[from] LogStorageError),
99
100    /// Error coming from the entry store.
101    #[error(transparent)]
102    EntryStoreError(#[from] EntryStorageError),
103
104    /// Error coming from the operation store.
105    #[error(transparent)]
106    OperationStoreError(#[from] OperationStorageError),
107
108    /// Error occurring when decoding entries.
109    #[error(transparent)]
110    DecodeEntryError(#[from] DecodeEntryError),
111
112    /// Error occurring when validating operations.
113    #[error(transparent)]
114    ValidateOperationError(#[from] ValidateOperationError),
115}