calimero_runtime/logic/
errors.rs

1use thiserror::Error as ThisError;
2use wasmer::MemoryAccessError;
3
4use crate::errors::{FunctionCallError, HostError, StorageError, VMRuntimeError};
5
6#[derive(Debug, ThisError)]
7#[non_exhaustive]
8pub enum VMLogicError {
9    #[error(transparent)]
10    HostError(#[from] HostError),
11    #[error(transparent)]
12    StorageError(StorageError),
13}
14
15impl From<MemoryAccessError> for VMLogicError {
16    fn from(_: MemoryAccessError) -> Self {
17        Self::HostError(HostError::InvalidMemoryAccess)
18    }
19}
20
21impl TryFrom<VMLogicError> for FunctionCallError {
22    type Error = VMRuntimeError;
23
24    fn try_from(err: VMLogicError) -> Result<Self, Self::Error> {
25        match err {
26            VMLogicError::StorageError(err) => Err(VMRuntimeError::StorageError(err)),
27            // todo! is it fine to panic the node on host errors
28            // todo! because that is a bug in the node, or do we
29            // todo! include it in the result? and record it on chain
30            // VMLogicError::HostError(HostError::Panic {
31            //     context: PanicContext::Host,
32            //     message,
33            // }) => Err(VMRuntimeError::HostError(err)),
34            VMLogicError::HostError(err) => Ok(Self::HostError(err)),
35        }
36    }
37}