aranya_runtime/vm_policy/
error.rs1use alloc::{format, string::String};
2
3use crate::{engine::EngineError, storage::StorageError};
4
5#[derive(Debug, thiserror::Error)]
6pub enum VmPolicyError {
8 #[error("deserialize error: {0}")]
11 Deserialization(#[from] postcard::Error),
12 #[error("engine error: {0}")]
14 EngineError(#[from] EngineError),
15 #[error("storage error: {0}")]
17 StorageError(#[from] StorageError),
18 #[error("atribute error: {0}")]
20 Attribute(#[from] AttributeError),
21 #[error("unknown error")]
23 Unknown,
24}
25
26#[derive(Debug, thiserror::Error, PartialEq, Eq)]
27#[error("{0}")]
28pub struct AttributeError(pub(crate) String);
29
30impl AttributeError {
31 pub(crate) fn type_mismatch(cmd: &str, attr: &str, expected: &str, actual: &str) -> Self {
32 Self(format!("{cmd}::{attr} should be {expected}, was {actual}"))
33 }
34
35 pub(crate) fn exclusive(cmd: &str, attr1: &str, attr2: &str) -> Self {
36 Self(format!(
37 "{cmd} has both exclusive attributes {attr1} and {attr2}"
38 ))
39 }
40
41 pub(crate) fn int_range(cmd: &str, attr: &str, min: i64, max: i64) -> Self {
42 Self(format!("{cmd}::{attr} must be within [{min}, {max}]"))
43 }
44
45 pub(crate) fn missing(cmd: &str, attrs: &str) -> Self {
46 Self(format!("{cmd} is missing {attrs}"))
47 }
48}