p2panda_rs/entry/
error.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3//! Error types for creating, encoding, decoding or validating entries and their regarding data
4//! types like sequence numbers or log ids.
5use thiserror::Error;
6
7/// Errors from `EntryBuilder` struct.
8#[derive(Error, Debug)]
9pub enum EntryBuilderError {
10    /// Handle errors from `entry::encode` module.
11    #[error(transparent)]
12    EncodeEntryError(#[from] EncodeEntryError),
13}
14
15/// Errors from `entry::encode` module.
16#[derive(Error, Debug)]
17pub enum EncodeEntryError {
18    /// Handle errors from `entry::validate` module.
19    #[error(transparent)]
20    ValidateEntryError(#[from] ValidateEntryError),
21
22    /// Handle errors from encoding `bamboo_rs_core_ed25519_yasmf` entries.
23    #[error(transparent)]
24    BambooEncodeError(#[from] bamboo_rs_core_ed25519_yasmf::entry::encode::Error),
25}
26
27/// Errors from `entry::decode` module.
28#[derive(Error, Debug)]
29pub enum DecodeEntryError {
30    /// Handle errors from `entry::validate` module.
31    #[error(transparent)]
32    ValidateEntryError(#[from] ValidateEntryError),
33
34    /// Handle errors from decoding `bamboo_rs_core_ed25519_yasmf` entries.
35    #[error(transparent)]
36    BambooDecodeError(#[from] bamboo_rs_core_ed25519_yasmf::entry::decode::Error),
37}
38
39/// Errors from `entry::validate` module.
40#[derive(Error, Debug)]
41#[allow(missing_copy_implementations)]
42pub enum ValidateEntryError {
43    /// Invalid configuration of backlink and skiplink hashes for this sequence number.
44    #[error("backlink and skiplink not valid for this sequence number")]
45    InvalidLinks,
46
47    /// Operation needs to match payload hash of encoded entry.
48    #[error("operation needs to match payload hash of encoded entry")]
49    PayloadHashMismatch,
50
51    /// Operation needs to match payload size of encoded entry.
52    #[error("operation needs to match payload size of encoded entry")]
53    PayloadSizeMismatch,
54
55    /// Backlink and skiplink hashes should be different.
56    #[error("backlink and skiplink are identical")]
57    BacklinkAndSkiplinkIdentical,
58
59    /// Backlink entry does not match log id.
60    #[error("entry is in log id {0} but backlink entry in log id {1}")]
61    WrongBacklinkLogId(u64, u64),
62
63    /// Skiplink entry does not match log id.
64    #[error("entry is in log id {0} but skiplink entry in log id {1}")]
65    WrongSkiplinkLogId(u64, u64),
66
67    /// Backlink entry from database has a different author.
68    #[error("claimed author does not match backlink entry")]
69    WrongBacklinkAuthor,
70
71    /// Backlink entry from database has a different hash.
72    #[error("claimed hash does not match backlink entry")]
73    WrongBacklinkHash,
74
75    /// Skiplink entry from database has a different author.
76    #[error("claimed author does not match skiplink entry")]
77    WrongSkiplinkAuthor,
78
79    /// Skiplink entry from database has a different hash.
80    #[error("claimed hash does not match skiplink entry")]
81    WrongSkiplinkHash,
82
83    /// Could not verify authorship of entry.
84    #[error("signature invalid")]
85    KeyPairError(#[from] crate::identity::error::KeyPairError),
86}
87
88/// Errors from `SeqNum` struct.
89#[derive(Error, Debug)]
90#[allow(missing_copy_implementations)]
91pub enum SeqNumError {
92    /// Sequence numbers are always positive.
93    #[error("sequence number can not be zero or negative")]
94    NotZeroOrNegative,
95
96    /// Conversion to u64 from string failed.
97    #[error("string contains invalid u64 value")]
98    InvalidU64String,
99}
100
101/// Errors from `LogId` struct.
102#[derive(Error, Debug)]
103#[allow(missing_copy_implementations)]
104pub enum LogIdError {
105    /// Conversion to u64 from string failed.
106    #[error("string contains invalid u64 value")]
107    InvalidU64String,
108}