aranya_runtime/vm_policy/
error.rs1use core::fmt;
2
3use crate::{engine::EngineError, storage::StorageError};
4
5#[derive(Debug)]
6pub enum VmPolicyError {
8 Deserialization(postcard::Error),
11 EngineError(EngineError),
13 StorageError(StorageError),
15 Unknown,
17}
18
19impl fmt::Display for VmPolicyError {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Self::Deserialization(e) => write!(f, "deserialize error: {e}"),
23 Self::EngineError(e) => write!(f, "engine error: {e}"),
24 Self::StorageError(e) => write!(f, "storage error: {e}"),
25 Self::Unknown => write!(f, "unknown error"),
26 }
27 }
28}
29
30impl core::error::Error for VmPolicyError {
31 fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
32 match self {
33 Self::EngineError(e) => Some(e),
34 Self::StorageError(e) => Some(e),
35 _ => None,
36 }
37 }
38}
39
40impl From<EngineError> for VmPolicyError {
41 fn from(value: EngineError) -> Self {
42 VmPolicyError::EngineError(value)
43 }
44}
45
46impl From<StorageError> for VmPolicyError {
47 fn from(value: StorageError) -> Self {
48 VmPolicyError::StorageError(value)
49 }
50}