use crate::{storage::RegisterAddress, NetworkAddress, PrettyPrintRecordKey};
use serde::{Deserialize, Serialize};
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Clone, PartialEq, Eq, Serialize, Deserialize, custom_debug::Debug)]
#[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("Register not found: {0}")]
RegisterNotFound(Box<RegisterAddress>),
#[error("The Register was already created by another owner: {0:?}")]
RegisterAlreadyClaimed(bls::PublicKey),
#[error("Peer {holder:?} cannot find Record {key:?}")]
RegisterRecordNotFound {
holder: Box<NetworkAddress>,
key: Box<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>),
}