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