use crate::{NetworkAddress, PrettyPrintRecordKey};
use libp2p::kad::store;
use serde::{Deserialize, Serialize};
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Error {
#[error("Could not obtain user's data directory")]
UserDataDirectoryNotObtainable,
#[error("Could not obtain port from MultiAddr")]
CouldNotObtainPortFromMultiAddr,
#[error("Could not parse RetryStrategy")]
ParseRetryStrategyError,
#[error("Could not obtain data dir")]
CouldNotObtainDataDir,
#[error("Chunk does not exist {0:?}")]
ChunkDoesNotExist(NetworkAddress),
#[error("Failed to deserialize hex ScratchpadAddress")]
ScratchpadHexDeserializeFailed,
#[error("Failed to derive CipherText from encrypted_data")]
ScratchpadCipherTextFailed,
#[error("Provided cypher text is invalid")]
ScratchpadCipherTextInvalid,
#[error("There was an error getting the storecost from kademlia store")]
GetStoreQuoteFailed,
#[error("There was an error generating the payment quote")]
QuoteGenerationFailed,
#[error("Peer {holder:?} cannot find Record {key:?}")]
ReplicatedRecordNotFound {
holder: Box<NetworkAddress>,
key: Box<NetworkAddress>,
},
#[error("Could not Serialize/Deserialize RecordHeader to/from Record")]
RecordHeaderParsingFailed,
#[error("Could not Serialize/Deserialize Record")]
RecordParsingFailed,
#[error("The record already exists, so do not charge for it: {0:?}")]
RecordExists(PrettyPrintRecordKey<'static>),
}
impl From<Error> for store::Error {
fn from(_err: Error) -> Self {
store::Error::ValueTooLarge
}
}
impl From<store::Error> for Error {
fn from(_err: store::Error) -> Self {
Error::RecordParsingFailed
}
}