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(
59        "Failed to verify payment with EVM network for record: {record_key:?}. Error: {error}"
60    )]
61    PaymentVerificationFailed {
62        record_key: PrettyPrintRecordKey<'static>,
63        error: ant_evm::payment_vault::error::Error,
64    },
65
66    // ---------- Chunk errors
67    #[error("Chunk is too large: {0} bytes, when max size is {1} bytes")]
68    OversizedChunk(usize, usize),
69
70    // ------------ Scratchpad Errors
71    #[error("A newer version of this Scratchpad already exists")]
72    IgnoringOutdatedScratchpadPut,
73
74    #[error("Scratchpad signature is invalid")]
75    InvalidScratchpadSignature,
76
77    #[error("Scratchpad too big: {0}, max size is {SCRATCHPAD_MAX_SIZE}")]
78    ScratchpadTooBig(usize),
79
80    // ---------- GraphEntry errors
81    #[error("There are no GraphEntries in the record: {0:?}")]
82    EmptyGraphEntry(PrettyPrintRecordKey<'static>),
83
84    // ---------- Pointer errors
85    #[error("Pointer signature is invalid")]
86    InvalidPointerSignature,
87}
88
89/// Internal node error.
90#[derive(Debug, Error)]
91#[allow(missing_docs)]
92pub enum Error {
93    #[error("Network error {0}")]
94    Network(#[from] ant_networking::NetworkError),
95
96    #[error("Failed to parse NodeEvent")]
97    NodeEventParsingFailed,
98
99    #[error("Failed to obtain node's current port")]
100    FailedToGetNodePort,
101
102    // ---------- Quote Errors
103    #[error("The content of the payment quote is invalid")]
104    InvalidQuoteContent,
105
106    #[error("The payment quote's signature is invalid")]
107    InvalidQuoteSignature,
108}