use thiserror::Error;
pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, Error)]
pub enum Error {
#[error("File read/write error: {0}")]
FileHandling(String),
#[error("Directory creation error: {0}")]
DirectoryHandling(String),
#[error("Failed to serialise section tree: {0}")]
Serialisation(String),
#[error("Failed to deserialise section tree: {0}")]
Deserialisation(String),
#[error("The provided SAP must belong to the genesis prefix")]
NonGenesisSap,
#[error("The provided signature cannot be verified while inserting into the SectionsDAG")]
InvalidSignature,
#[error("Key not found in the SectionsDAG: {0:?}")]
KeyNotFound(bls::PublicKey),
#[error("The 'to' or 'from' key is not present in the same branch of the SectionsDAG")]
InvalidBranch,
#[error("The SectionsDAG should contain a single branch")]
MultipleBranchError,
#[error("Proof chain cannot be trusted: {0}")]
UntrustedProofChain(String),
#[error("Provided proof_chain doesn't cover the SAP's key we currently know: {0}")]
SAPKeyNotCoveredByProofChain(String),
#[error("Section authority provider cannot be trusted: {0}")]
UntrustedSectionAuthProvider(String),
#[error("The genesis key of the provided SectionTree is invalid: {0:?}")]
InvalidGenesisKey(bls::PublicKey),
#[error("A relocating node provided invalid relocation proof.")]
InvalidRelocationProof,
#[error("A signature share is invalid.")]
InvalidSignatureShare,
#[error("The secret key share is missing for public key {0:?}")]
MissingSecretKeyShare(bls::PublicKey),
#[error("Invalid payload")]
InvalidPayload,
#[error("The section is currently set to not allow taking any new node")]
TryJoinLater,
#[error("No matching Section")]
NoMatchingSection,
#[error(
"A JoinResponse was received after we've already had a node on this socket join the the network. It has been ignored."
)]
ExistingMemberSocketAddrConflict,
#[error(
"A JoinResponse was received after we've a node with this name has joined the network. It has been ignored."
)]
ExistingMemberNameConflict,
#[error("The node in question is not a member of the section")]
NotAMember,
#[error("Request does not match the section prefix")]
WrongSection,
#[error("Consensus({0:?})")]
Consensus(#[from] sn_consensus::Error),
#[error("An archived node attempted to rejoin the section")]
ArchivedNodeRejoined,
#[error("We are behind, need to request AE update")]
AEOutdated,
}