casper_storage/tracking_copy/
error.rs1use thiserror::Error;
2
3use crate::data_access_layer::balance::BalanceFailure;
4use casper_types::{
5 account::{AddKeyFailure, RemoveKeyFailure, SetThresholdFailure, UpdateKeyFailure},
6 bytesrepr, system, ApiError, CLType, CLValueError, Key, StoredValueTypeMismatch,
7};
8
9#[derive(Error, Debug, Clone)]
11#[non_exhaustive]
12pub enum Error {
13 #[error("Storage error: {}", _0)]
15 Storage(crate::global_state::error::Error),
16 #[error("Serialization error: {}", _0)]
18 BytesRepr(bytesrepr::Error),
19 #[error("Named key {} not found", _0)]
21 NamedKeyNotFound(String),
22 #[error("Key {} not found", _0)]
24 KeyNotFound(Key),
25 #[error("Account {:?} not found", _0)]
27 AccountNotFound(Key),
28 #[error("{}", _0)]
30 TypeMismatch(StoredValueTypeMismatch),
31 #[error("{}", _0)]
33 Api(ApiError),
34 #[error("{}", _0)]
36 AddKeyFailure(AddKeyFailure),
37 #[error("{}", _0)]
39 RemoveKeyFailure(RemoveKeyFailure),
40 #[error("{}", _0)]
42 UpdateKeyFailure(UpdateKeyFailure),
43 #[error("{}", _0)]
45 SetThresholdFailure(SetThresholdFailure),
46 #[error("{}", _0)]
48 SystemContract(system::Error),
49 #[error("Deployment authorization failure")]
51 DeploymentAuthorizationFailure,
52 #[error("{0}")]
54 CLValue(CLValueError),
55 #[error("Unexpected variant of a stored value")]
57 UnexpectedStoredValueVariant,
58 #[error("Missing system contract hash: {0}")]
60 MissingSystemContractHash(String),
61 #[error("Invalid key {0}")]
63 UnexpectedKeyVariant(Key),
64 #[error("Query attempted a circular reference: {0}")]
66 CircularReference(String),
67 #[error("Query exceeded depth limit: {depth}")]
69 QueryDepthLimit {
70 depth: u64,
72 },
73 #[error("Missing bid: {0}")]
75 MissingBid(Key),
76 #[error("Authorization error")]
78 Authorization,
79 #[error("Value not found")]
81 ValueNotFound(String),
82 #[error("Balance calculation failure")]
84 Balance(BalanceFailure),
85 #[error("Contract {:?} not found", _0)]
87 ContractNotFound(Key),
88 #[error("flag")]
89 AddressableEntityDisable,
91}
92
93impl Error {
94 pub fn type_mismatch(expected: CLType, found: CLType) -> Error {
96 Error::TypeMismatch(StoredValueTypeMismatch::new(
97 format!("{:?}", expected),
98 format!("{:?}", found),
99 ))
100 }
101}
102
103impl From<bytesrepr::Error> for Error {
104 fn from(e: bytesrepr::Error) -> Self {
105 Error::BytesRepr(e)
106 }
107}
108
109impl From<AddKeyFailure> for Error {
110 fn from(err: AddKeyFailure) -> Self {
111 Error::AddKeyFailure(err)
112 }
113}
114
115impl From<RemoveKeyFailure> for Error {
116 fn from(err: RemoveKeyFailure) -> Self {
117 Error::RemoveKeyFailure(err)
118 }
119}
120
121impl From<UpdateKeyFailure> for Error {
122 fn from(err: UpdateKeyFailure) -> Self {
123 Error::UpdateKeyFailure(err)
124 }
125}
126
127impl From<SetThresholdFailure> for Error {
128 fn from(err: SetThresholdFailure) -> Self {
129 Error::SetThresholdFailure(err)
130 }
131}
132
133impl From<CLValueError> for Error {
134 fn from(e: CLValueError) -> Self {
135 Error::CLValue(e)
136 }
137}
138
139impl From<crate::global_state::error::Error> for Error {
140 fn from(gse: crate::global_state::error::Error) -> Self {
141 Error::Storage(gse)
142 }
143}