Skip to main content

p2panda_core/operation/
errors.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use thiserror::Error;
4
5use crate::logs::SeqNum;
6use crate::operation::Version;
7
8#[derive(Debug, Error)]
9pub enum HeaderError {
10    #[error("failed decoding CBOR byte string for header: {0}")]
11    DecodingHeader(cbor_core::Error),
12
13    #[error("failed decoding CBOR byte string for extensions: {0}")]
14    DecodingExtensions(cbor_core::SerdeError),
15
16    #[error("expected CBOR array for header: {0}")]
17    UnexpectedHeaderType(cbor_core::Error),
18
19    #[error("missing \"{0}\" field in header")]
20    MissingField(&'static str),
21
22    #[error("unexpected \"{0}\" field type for \"{0}\"")]
23    UnexpectedFieldType(cbor_core::Error, &'static str),
24
25    #[error("invalid verifying key: {0}")]
26    InvalidVerifyingKey(crate::identity::IdentityError),
27
28    #[error("invalid bytes length for \"{0}\", expected {1}, got {2} bytes")]
29    InvalidBytesLen(&'static str, usize, usize),
30
31    #[error("operation version {0} is not supported, needs to be <= {1}")]
32    UnsupportedVersion(Version, Version),
33
34    #[error("invalid signature")]
35    InvalidSignature,
36
37    #[error("unexpected excessive fields in header")]
38    ExcessiveFields,
39
40    #[error("didn't expect extensions but header contained excessive field")]
41    UnexpectedExtensions,
42
43    #[error("expected extensions but header didn't contain any")]
44    MissingExtensions,
45
46    #[error("failed encoding CBOR byte string for extensions: {0}")]
47    EncodingExtensions(cbor_core::SerdeError),
48}
49
50#[derive(Clone, Debug, Error)]
51pub enum OperationError {
52    #[error("operation version {0} is not supported, needs to be <= {1}")]
53    UnsupportedVersion(Version, Version),
54
55    #[error("operation needs to be signed")]
56    MissingSignature,
57
58    #[error("signature does not match claimed public key")]
59    SignatureMismatch,
60
61    #[error("sequence number can't be 0 when backlink is given")]
62    SeqNumMismatch,
63
64    #[error("payload hash and -size need to be defined together")]
65    InconsistentPayloadInfo,
66
67    #[error("needs payload hash in header when body is given")]
68    MissingPayloadHash,
69
70    #[error("payload hash and size do not match given body")]
71    PayloadMismatch,
72
73    #[error("logs can not contain operations of different authors")]
74    TooManyAuthors,
75
76    #[error("expected sequence number {0} but found {1}")]
77    SeqNumNonIncremental(SeqNum, SeqNum),
78
79    #[error("expected backlink but none was given")]
80    BacklinkMissing,
81
82    #[error("given backlink did not match previous operation")]
83    BacklinkMismatch,
84}