casper_storage/tracking_copy/
error.rs

1use 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/// Possible tracking copy errors.
10#[derive(Error, Debug, Clone)]
11#[non_exhaustive]
12pub enum Error {
13    /// Storage error.
14    #[error("Storage error: {}", _0)]
15    Storage(crate::global_state::error::Error),
16    /// Failed to (de)serialize bytes.
17    #[error("Serialization error: {}", _0)]
18    BytesRepr(bytesrepr::Error),
19    /// Unable to find named key.
20    #[error("Named key {} not found", _0)]
21    NamedKeyNotFound(String),
22    /// Unable to find a key.
23    #[error("Key {} not found", _0)]
24    KeyNotFound(Key),
25    /// Unable to find an account.
26    #[error("Account {:?} not found", _0)]
27    AccountNotFound(Key),
28    /// Type mismatch error.
29    #[error("{}", _0)]
30    TypeMismatch(StoredValueTypeMismatch),
31    /// ApiError.
32    #[error("{}", _0)]
33    Api(ApiError),
34    /// Error adding an associated key.
35    #[error("{}", _0)]
36    AddKeyFailure(AddKeyFailure),
37    /// Error removing an associated key.
38    #[error("{}", _0)]
39    RemoveKeyFailure(RemoveKeyFailure),
40    /// Error updating an associated key.
41    #[error("{}", _0)]
42    UpdateKeyFailure(UpdateKeyFailure),
43    /// Error setting threshold on associated key.
44    #[error("{}", _0)]
45    SetThresholdFailure(SetThresholdFailure),
46    /// Error executing system contract.
47    #[error("{}", _0)]
48    SystemContract(system::Error),
49    /// Weight of all used associated keys does not meet account's deploy threshold.
50    #[error("Deployment authorization failure")]
51    DeploymentAuthorizationFailure,
52    /// Error converting a CLValue.
53    #[error("{0}")]
54    CLValue(CLValueError),
55    /// Unexpected variant of a stored value.
56    #[error("Unexpected variant of a stored value")]
57    UnexpectedStoredValueVariant,
58    /// Missing system contract hash.
59    #[error("Missing system contract hash: {0}")]
60    MissingSystemContractHash(String),
61    /// Invalid key
62    #[error("Invalid key {0}")]
63    UnexpectedKeyVariant(Key),
64    /// Circular reference error.
65    #[error("Query attempted a circular reference: {0}")]
66    CircularReference(String),
67    /// Depth limit reached.
68    #[error("Query exceeded depth limit: {depth}")]
69    QueryDepthLimit {
70        /// Current depth limit.
71        depth: u64,
72    },
73    /// Missing bid.
74    #[error("Missing bid: {0}")]
75    MissingBid(Key),
76    /// Not authorized.
77    #[error("Authorization error")]
78    Authorization,
79    /// The value wasn't found.
80    #[error("Value not found")]
81    ValueNotFound(String),
82    /// Balance calculation failure.
83    #[error("Balance calculation failure")]
84    Balance(BalanceFailure),
85    /// Unable to find a contract.
86    #[error("Contract {:?} not found", _0)]
87    ContractNotFound(Key),
88    #[error("flag")]
89    /// Attempted to fetch an entity or an associated record
90    AddressableEntityDisable,
91}
92
93impl Error {
94    /// Returns new type mismatch error.
95    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}