p2panda_rs/storage_provider/
error.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3//! Errors from storage provider and associated traits.
4use crate::document::error::DocumentBuilderError;
5use crate::document::{DocumentId, DocumentViewId};
6use crate::entry::error::{LogIdError, SeqNumError, ValidateEntryError};
7use crate::hash::error::HashError;
8use crate::hash::Hash;
9use crate::identity::error::PublicKeyError;
10use crate::operation::error::ValidateOperationError;
11use crate::operation::OperationId;
12
13/// Data validation errors which can occur in the storage traits.
14#[derive(thiserror::Error, Debug)]
15pub enum ValidationError {
16    /// Error returned from validating p2panda-rs `PublicKey` data types.
17    #[error(transparent)]
18    AuthorValidation(#[from] PublicKeyError),
19
20    /// Error returned from validating p2panda-rs `Hash` data types.
21    #[error(transparent)]
22    HashValidation(#[from] HashError),
23
24    /// Error returned from validating p2panda-rs `Entry` data types.
25    #[error(transparent)]
26    EntryValidation(#[from] ValidateEntryError),
27
28    /// Error returned from validating p2panda-rs `Operation` data types.
29    #[error(transparent)]
30    OperationValidation(#[from] ValidateOperationError),
31
32    /// Error returned from validating p2panda-rs `LogId` data types.
33    #[error(transparent)]
34    LogIdValidation(#[from] LogIdError),
35
36    /// Error returned from validating p2panda-rs `SeqNum` data types.
37    #[error(transparent)]
38    SeqNumValidation(#[from] SeqNumError),
39
40    /// Error returned from validating Bamboo entries.
41    #[error(transparent)]
42    BambooValidation(#[from] bamboo_rs_core_ed25519_yasmf::verify::Error),
43}
44
45/// `LogStorage` errors.
46#[derive(thiserror::Error, Debug)]
47pub enum LogStorageError {
48    /// Catch all error which implementers can use for passing their own errors up the chain.
49    #[error("Error occured during `LogStorage` request in storage provider: {0}")]
50    Custom(String),
51}
52
53/// `EntryStorage` errors.
54#[derive(thiserror::Error, Debug)]
55pub enum EntryStorageError {
56    /// Catch all error which implementers can use for passing their own errors up the chain.
57    #[error("Error occured during `EntryStorage` request in storage provider: {0}")]
58    Custom(String),
59
60    /// Error which occurs if entries' expected backlink is missing from the database.
61    #[error("Could not find expected backlink in database for entry with id: {0}")]
62    ExpectedBacklinkMissing(Hash),
63
64    /// Error which occurs if entries' encoded backlink hash does not match the expected one
65    /// present in the database.
66    #[error(
67        "The backlink hash encoded in the entry: {0} did not match the expected backlink hash"
68    )]
69    InvalidBacklinkPassed(Hash),
70
71    /// Error which occurs if entries' expected skiplink is missing from the database.
72    #[error("Could not find expected skiplink in database for entry with id: {0}")]
73    ExpectedSkiplinkMissing(Hash),
74
75    /// Error which occurs if entries' encoded skiplink hash does not match the expected one
76    /// present in the database.
77    #[error("The skiplink hash encoded in the entry: {0} did not match the known hash of the skiplink target")]
78    InvalidSkiplinkPassed(Hash),
79
80    /// Error which originates in `determine_skiplink` if the expected skiplink is missing.
81    #[error("Could not find expected skiplink entry in database")]
82    ExpectedNextSkiplinkMissing,
83
84    /// Error which originates in `get_all_skiplink_entries_for_entry` if an entry in
85    /// the requested cert pool is missing.
86    #[error("Entry required for requested certificate pool missing at seq num: {0}")]
87    CertPoolEntryMissing(u64),
88
89    /// Error returned from validating p2panda-rs `EntrySigned` data types.
90    #[error(transparent)]
91    ValidationError(#[from] ValidationError),
92}
93
94/// `OperationStore` errors.
95#[derive(thiserror::Error, Debug)]
96pub enum OperationStorageError {
97    /// Catch all error which implementers can use for passing their own errors up the chain.
98    #[error("Error occured in OperationStore: {0}")]
99    Custom(String),
100
101    /// A fatal error occured when performing a storage query.
102    #[error("A fatal error occured in OperationStore: {0}")]
103    FatalStorageError(String),
104
105    /// Error returned when insertion of an operation is not possible due to database constraints.
106    #[error("Error occured when inserting an operation with id {0:?} into storage")]
107    InsertionError(OperationId),
108}
109
110/// `DocumentStore` errors.
111#[derive(thiserror::Error, Debug)]
112pub enum DocumentStorageError {
113    /// Catch all error which implementers can use for passing their own errors up the chain.
114    #[error("Error occured in DocumentStore: {0}")]
115    Custom(String),
116
117    /// A fatal error occured when performing a storage query.
118    #[error("A fatal error occured in DocumentStore: {0}")]
119    FatalStorageError(String),
120
121    /// Error which originates in `insert_document_view()` when the insertion fails.
122    #[error("Error occured when inserting a document view with id {0:?} into storage")]
123    DocumentViewInsertionError(DocumentViewId),
124
125    /// Error which originates in `insert_document()` when the insertion fails.
126    #[error("Error occured when inserting a document with id {0:?} into storage")]
127    DocumentInsertionError(DocumentId),
128
129    /// Error returned from validating p2panda-rs `Operation` data types.
130    #[error(transparent)]
131    OperationValidation(#[from] ValidateOperationError),
132
133    /// Error returned from `OperationStorage`.
134    #[error(transparent)]
135    OperationStorageError(#[from] OperationStorageError),
136
137    /// Error returned from `DocumentBuilder`.
138    #[error(transparent)]
139    DocumentBuilderError(#[from] DocumentBuilderError),
140}