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("Failed to deserialize hex ScratchpadAddress")]
38 ScratchpadHexDeserializeFailed,
39 #[error("Failed to derive CipherText from encrypted_data")]
41 ScratchpadCipherTextFailed,
42 #[error("Provided cypher text is invalid")]
44 ScratchpadCipherTextInvalid,
45
46 #[error("There was an error getting the storecost from kademlia store")]
48 GetStoreQuoteFailed,
49 #[error("There was an error generating the payment quote")]
50 QuoteGenerationFailed,
51
52 #[error("Peer {holder:?} cannot find Record {key:?}")]
55 ReplicatedRecordNotFound {
56 holder: Box<NetworkAddress>,
58 key: Box<NetworkAddress>,
60 },
61
62 #[error("Could not Serialize/Deserialize RecordHeader to/from Record")]
65 RecordHeaderParsingFailed,
66 #[error("Could not Serialize/Deserialize Record")]
68 RecordParsingFailed,
69 #[error("The record already exists, so do not charge for it: {0:?}")]
71 RecordExists(PrettyPrintRecordKey<'static>),
72}
73
74impl From<Error> for store::Error {
75 fn from(_err: Error) -> Self {
76 store::Error::ValueTooLarge
77 }
78}
79
80impl From<store::Error> for Error {
81 fn from(_err: store::Error) -> Self {
82 Error::RecordParsingFailed
83 }
84}