pub use crate::messaging::data::Error as ErrorMessage;
use crate::messaging::{
data::{CmdError, OperationId, QueryResponse},
Error as MessagingError,
};
use crate::types::Error as DtError;
use std::io;
use thiserror::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[allow(clippy::large_enum_variant)]
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
#[error("Error on aggregating signatures from network")]
Aggregation(String),
#[error("Asymmetric key decryption failure")]
AsymmetricDecipherFailure,
#[error("Symmetric key decryption failure")]
SymmetricDecipherFailure,
#[error("Unexpected data received")]
ReceivedUnexpectedData,
#[error("Unexpected event received")]
ReceivedUnexpectedEvent,
#[error("Problem querying elder")]
ElderQuery,
#[error("Problem connecting to elder")]
ElderConnection,
#[error("Client has not yet acquired any network knowledge, so anything sent is guaranteed to have a lengthy AE process")]
NoNetworkKnowledge,
#[error("An error was returned from IncomingMessages on one of our connections")]
IncomingMessages,
#[error(
"Problem connecting to sufficient elders. A supermajority of responses is unobtainable. {0} were connected to, {1} needed."
)]
InsufficientElderConnections(usize, usize),
#[error("Problem receiving query via qp2p")]
ReceivingQuery,
#[error("Problem sending query via qp2p")]
SendingQuery,
#[error("Query timed out")]
QueryTimedOut,
#[error("Problem receiving query internally in sn_client")]
QueryReceiverError,
#[error("Failed to obtain any response")]
NoResponse,
#[error("No BLS Section Key available")]
NoBlsSectionKey,
#[error("We do not have a section prefix.")]
NoSectionPrefixKnown,
#[error("Unexpected message type receivied while joining: {0}")]
UnexpectedMessageOnJoin(String),
#[error("Expected public permission set")]
NotPublicPermissions,
#[error("Expected private permission set")]
NotPrivatePermissions,
#[error("Could not listen on elder connection")]
NoElderListenerEstablished,
#[error("Incorrect user permissions were returned")]
IncorrectPermissions,
#[error("Could not retrieve the operation id of a query response")]
UnknownOperationId,
#[error("Unexpected response received when querying {0:?}")]
UnexpectedQueryResponse(QueryResponse),
#[error("Simulated payouts unavailable without 'simualted-payouts' feature flag at build")]
NotBuiltWithSimulatedPayouts,
#[error(transparent)]
NetworkDataError(#[from] DtError),
#[error(
"Error received from the network: {:?} Operationid: {:?}",
source,
op_id
)]
ErrorMessage {
source: ErrorMessage,
op_id: OperationId,
},
#[error(transparent)]
MessagingProtocol(#[from] MessagingError),
#[error(transparent)]
SelfEncryption(#[from] self_encryption::Error),
#[error(transparent)]
ConfigError(#[from] serde_json::Error),
#[error(transparent)]
IoError(#[from] io::Error),
#[error(transparent)]
EndpointSetup(#[from] qp2p::ClientEndpointError),
#[error(transparent)]
QuicP2p(#[from] qp2p::RpcError),
#[error(transparent)]
Serialisation(#[from] Box<bincode::ErrorKind>),
#[error("Sled error:: {0}")]
Sled(#[from] sled::Error),
#[error("Database error:: {0}")]
Database(#[from] crate::dbs::Error),
#[error("Generic error")]
Generic(String),
#[error("Not enough chunks! Required {}, but we have {}.)", _0, _1)]
NotEnoughChunks(usize, usize),
#[error("Not all data was chunked! Required {}, but we have {}.)", _0, _1)]
NotAllDataWasChunked(usize, usize),
#[error("Invalid position or length: {0}")]
InvalidPositionOrLength(String),
}
impl From<(CmdError, OperationId)> for Error {
fn from((error, op_id): (CmdError, OperationId)) -> Self {
let CmdError::Data(source) = error;
Error::ErrorMessage { source, op_id }
}
}
impl From<(ErrorMessage, OperationId)> for Error {
fn from((source, op_id): (ErrorMessage, OperationId)) -> Self {
Self::ErrorMessage { source, op_id }
}
}
impl From<qp2p::SendError> for Error {
fn from(error: qp2p::SendError) -> Self {
Self::QuicP2p(error.into())
}
}
impl From<qp2p::RecvError> for Error {
fn from(error: qp2p::RecvError) -> Self {
Self::QuicP2p(error.into())
}
}