1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use core::fmt;

use parity_wasm::elements;

use engine_shared::TypeMismatch;
use types::{
    account::{AddKeyFailure, RemoveKeyFailure, SetThresholdFailure, UpdateKeyFailure},
    bytesrepr, system_contract_errors, AccessRights, CLValueError, Key, URef,
};

use crate::resolvers::error::ResolverError;

#[derive(Debug)]
pub enum Error {
    Interpreter(wasmi::Error),
    Storage(engine_storage::error::Error),
    BytesRepr(bytesrepr::Error),
    KeyNotFound(Key),
    AccountNotFound(Key),
    TypeMismatch(TypeMismatch),
    InvalidAccess {
        required: AccessRights,
    },
    ForgedReference(URef),
    URefNotFound(String),
    FunctionNotFound(String),
    ParityWasm(elements::Error),
    GasLimit,
    Ret(Vec<URef>),
    Rng(rand::Error),
    Resolver(ResolverError),
    /// Reverts execution with a provided status
    Revert(u32),
    AddKeyFailure(AddKeyFailure),
    RemoveKeyFailure(RemoveKeyFailure),
    UpdateKeyFailure(UpdateKeyFailure),
    SetThresholdFailure(SetThresholdFailure),
    SystemContract(system_contract_errors::Error),
    DeploymentAuthorizationFailure,
    ExpectedReturnValue,
    UnexpectedReturnValue,
    InvalidContext,
    IncompatibleProtocolMajorVersion {
        expected: u32,
        actual: u32,
    },
    CLValue(CLValueError),
    HostBufferEmpty,
    UnsupportedWasmStart,
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}

impl wasmi::HostError for Error {}

impl From<!> for Error {
    fn from(error: !) -> Self {
        match error {}
    }
}

impl From<wasmi::Error> for Error {
    fn from(e: wasmi::Error) -> Self {
        Error::Interpreter(e)
    }
}

impl From<engine_storage::error::Error> for Error {
    fn from(e: engine_storage::error::Error) -> Self {
        Error::Storage(e)
    }
}

impl From<bytesrepr::Error> for Error {
    fn from(e: bytesrepr::Error) -> Self {
        Error::BytesRepr(e)
    }
}

impl From<elements::Error> for Error {
    fn from(e: elements::Error) -> Self {
        Error::ParityWasm(e)
    }
}

impl From<ResolverError> for Error {
    fn from(err: ResolverError) -> Self {
        Error::Resolver(err)
    }
}

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<system_contract_errors::Error> for Error {
    fn from(error: system_contract_errors::Error) -> Self {
        Error::SystemContract(error)
    }
}

impl From<CLValueError> for Error {
    fn from(e: CLValueError) -> Self {
        Error::CLValue(e)
    }
}