1use crate::{NetworkAddress, PrettyPrintRecordKey};
10use libp2p::kad::store;
11use serde::{Deserialize, Serialize};
12use thiserror::Error;
13
14pub type Result<T> = std::result::Result<T, Error>;
16
17#[derive(Error, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
19#[non_exhaustive]
20pub enum Error {
21 #[error("Could not obtain user's data directory")]
23 UserDataDirectoryNotObtainable,
24 #[error("Could not obtain port from MultiAddr")]
25 CouldNotObtainPortFromMultiAddr,
26 #[error("Could not parse RetryStrategy")]
27 ParseRetryStrategyError,
28 #[error("Could not obtain data dir")]
29 CouldNotObtainDataDir,
30
31 #[error("Chunk does not exist {0:?}")]
33 ChunkDoesNotExist(NetworkAddress),
34
35 #[error("Chunk is too large: {0} bytes, when max size is {1} bytes")]
37 OversizedChunk(usize, usize),
38
39 #[error("Failed to deserialize hex ScratchpadAddress")]
42 ScratchpadHexDeserializeFailed,
43 #[error("Failed to derive CipherText from encrypted_data")]
45 ScratchpadCipherTextFailed,
46 #[error("Provided cypher text is invalid")]
48 ScratchpadCipherTextInvalid,
49
50 #[error("There was an error getting the storecost from kademlia store")]
52 GetStoreQuoteFailed,
53 #[error("There was an error generating the payment quote")]
54 QuoteGenerationFailed,
55
56 #[error("Peer {holder:?} cannot find Record {key:?}")]
59 ReplicatedRecordNotFound {
60 holder: Box<NetworkAddress>,
62 key: Box<NetworkAddress>,
64 },
65
66 #[error("Could not Serialize/Deserialize RecordHeader to/from Record")]
69 RecordHeaderParsingFailed,
70 #[error("Could not Serialize/Deserialize Record")]
72 RecordParsingFailed,
73 #[error("The record already exists, so do not charge for it: {0:?}")]
75 RecordExists(PrettyPrintRecordKey<'static>),
76}
77
78impl From<Error> for store::Error {
79 fn from(_err: Error) -> Self {
80 store::Error::ValueTooLarge
81 }
82}
83
84impl From<store::Error> for Error {
85 fn from(_err: store::Error) -> Self {
86 Error::RecordParsingFailed
87 }
88}