use thiserror::Error;
use crate::data_access_layer::balance::BalanceFailure;
use casper_types::{
account::{AddKeyFailure, RemoveKeyFailure, SetThresholdFailure, UpdateKeyFailure},
bytesrepr, system, ApiError, CLType, CLValueError, Key, StoredValueTypeMismatch,
};
#[derive(Error, Debug, Clone)]
#[non_exhaustive]
pub enum Error {
#[error("Storage error: {}", _0)]
Storage(crate::global_state::error::Error),
#[error("Serialization error: {}", _0)]
BytesRepr(bytesrepr::Error),
#[error("Named key {} not found", _0)]
NamedKeyNotFound(String),
#[error("Key {} not found", _0)]
KeyNotFound(Key),
#[error("Account {:?} not found", _0)]
AccountNotFound(Key),
#[error("{}", _0)]
TypeMismatch(StoredValueTypeMismatch),
#[error("{}", _0)]
Api(ApiError),
#[error("{}", _0)]
AddKeyFailure(AddKeyFailure),
#[error("{}", _0)]
RemoveKeyFailure(RemoveKeyFailure),
#[error("{}", _0)]
UpdateKeyFailure(UpdateKeyFailure),
#[error("{}", _0)]
SetThresholdFailure(SetThresholdFailure),
#[error("{}", _0)]
SystemContract(system::Error),
#[error("Deployment authorization failure")]
DeploymentAuthorizationFailure,
#[error("{0}")]
CLValue(CLValueError),
#[error("Unexpected variant of a stored value")]
UnexpectedStoredValueVariant,
#[error("Missing system contract hash: {0}")]
MissingSystemContractHash(String),
#[error("Invalid key {0}")]
UnexpectedKeyVariant(Key),
#[error("Query attempted a circular reference: {0}")]
CircularReference(String),
#[error("Query exceeded depth limit: {depth}")]
QueryDepthLimit {
depth: u64,
},
#[error("Missing bid: {0}")]
MissingBid(Key),
#[error("Authorization error")]
Authorization,
#[error("Value not found")]
ValueNotFound(String),
#[error("Balance calculation failure")]
Balance(BalanceFailure),
#[error("Contract {:?} not found", _0)]
ContractNotFound(Key),
#[error("flag")]
AddressableEntityDisable,
}
impl Error {
pub fn type_mismatch(expected: CLType, found: CLType) -> Error {
Error::TypeMismatch(StoredValueTypeMismatch::new(
format!("{:?}", expected),
format!("{:?}", found),
))
}
}
impl From<bytesrepr::Error> for Error {
fn from(e: bytesrepr::Error) -> Self {
Error::BytesRepr(e)
}
}
impl From<AddKeyFailure> for Error {
fn from(err: AddKeyFailure) -> Self {
Error::AddKeyFailure(err)
}
}
impl From<RemoveKeyFailure> for Error {
fn from(err: RemoveKeyFailure) -> Self {
Error::RemoveKeyFailure(err)
}
}
impl From<UpdateKeyFailure> for Error {
fn from(err: UpdateKeyFailure) -> Self {
Error::UpdateKeyFailure(err)
}
}
impl From<SetThresholdFailure> for Error {
fn from(err: SetThresholdFailure) -> Self {
Error::SetThresholdFailure(err)
}
}
impl From<CLValueError> for Error {
fn from(e: CLValueError) -> Self {
Error::CLValue(e)
}
}
impl From<crate::global_state::error::Error> for Error {
fn from(gse: crate::global_state::error::Error) -> Self {
Error::Storage(gse)
}
}