ant_node/
error.rs

1// Copyright 2024 MaidSafe.net limited.
2//
3// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
4// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
5// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
6// KIND, either express or implied. Please review the Licences for the specific language governing
7// permissions and limitations relating to use of the SAFE Network Software.
8
9use ant_protocol::PrettyPrintRecordKey;
10use libp2p::PeerId;
11use thiserror::Error;
12
13pub(super) type Result<T, E = Error> = std::result::Result<T, E>;
14
15const SCRATCHPAD_MAX_SIZE: usize = ant_protocol::storage::Scratchpad::MAX_SIZE;
16
17/// Put validation errors.
18#[derive(Debug, Error)]
19#[allow(missing_docs)]
20pub enum PutValidationError {
21    #[error("Error while requesting data from the local swarm")]
22    LocalSwarmError,
23
24    #[error("The record header cannot be deserialized")]
25    InvalidRecordHeader,
26
27    #[error("The record cannot be deserialized to the expected type")]
28    InvalidRecord(PrettyPrintRecordKey<'static>),
29
30    #[error("The Record::key does not match with the key derived from Record::value")]
31    RecordKeyMismatch,
32
33    #[error("Failed to serialize the record")]
34    RecordSerializationFailed(PrettyPrintRecordKey<'static>),
35
36    // ---------- Payment errors
37    #[error("The record did not contain any payments: {0:?}")]
38    NoPayment(PrettyPrintRecordKey<'static>),
39
40    /// At this point in replication flows, payment is unimportant and should not be supplied
41    #[error("Record should not be a `WithPayment` type: {0:?}")]
42    UnexpectedRecordWithPayment(PrettyPrintRecordKey<'static>),
43
44    #[error("Our node did not receive any payment for record: {0:?}")]
45    PaymentNotMadeToOurNode(PrettyPrintRecordKey<'static>),
46
47    #[error("The payment was made to an incorrect data type: {0:?}")]
48    PaymentMadeToIncorrectDataType(PrettyPrintRecordKey<'static>),
49
50    #[error(
51        "The payment quote has out of range payees for record: {record_key:?}. Payees: {payees:?}"
52    )]
53    PaymentQuoteOutOfRange {
54        record_key: PrettyPrintRecordKey<'static>,
55        payees: Vec<PeerId>,
56    },
57
58    #[error("Failed to verify payment with EVM network for record: {record_key:?}. Error: {error}")]
59    PaymentVerificationFailed {
60        record_key: PrettyPrintRecordKey<'static>,
61        error: ant_evm::payment_vault::error::Error,
62    },
63
64    // ---------- Chunk errors
65    #[error("Chunk is too large: {0} bytes, when max size is {1} bytes")]
66    OversizedChunk(usize, usize),
67
68    // ------------ Mutable data errors
69    #[error("Rejected outdated record: with counter {counter}, expected any above {expected}")]
70    OutdatedRecordCounter { counter: u64, expected: u64 },
71
72    #[error("Scratchpad signature is invalid")]
73    InvalidScratchpadSignature,
74
75    #[error("Scratchpad too big: {0}, max size is {SCRATCHPAD_MAX_SIZE}")]
76    ScratchpadTooBig(usize),
77
78    // ---------- GraphEntry errors
79    #[error("There are no GraphEntries in the record: {0:?}")]
80    EmptyGraphEntry(PrettyPrintRecordKey<'static>),
81
82    // ---------- Pointer errors
83    #[error("Pointer signature is invalid")]
84    InvalidPointerSignature,
85}
86
87/// Internal node error.
88#[derive(Debug, Error)]
89#[allow(missing_docs)]
90pub enum Error {
91    #[error("Network error {0}")]
92    Network(#[from] crate::networking::NetworkError),
93
94    #[error("Failed to parse NodeEvent")]
95    NodeEventParsingFailed,
96
97    #[error("Failed to obtain node's current port")]
98    FailedToGetNodePort,
99
100    // ---------- Quote Errors
101    #[error("The content of the payment quote is invalid")]
102    InvalidQuoteContent,
103
104    #[error("The payment quote's signature is invalid")]
105    InvalidQuoteSignature,
106}