borderless_runtime/
error.rs1use borderless::{AgentId, ContractId};
2use thiserror::Error;
3
4pub type Result<T> = std::result::Result<T, Error>;
5
6#[derive(Debug, Error)]
7#[error(transparent)]
8pub struct Error {
9 kind: ErrorKind,
10}
11
12impl Error {
13 pub fn msg(msg: impl AsRef<str>) -> Self {
14 ErrorKind::Msg(msg.as_ref().to_string()).into()
15 }
16}
17
18impl From<ErrorKind> for Error {
19 fn from(value: ErrorKind) -> Self {
20 Error { kind: value }
21 }
22}
23
24impl From<borderless_kv_store::Error> for Error {
25 fn from(value: borderless_kv_store::Error) -> Self {
26 ErrorKind::from(value).into()
27 }
28}
29
30impl From<postcard::Error> for Error {
31 fn from(value: postcard::Error) -> Self {
32 ErrorKind::from(value).into()
33 }
34}
35
36impl From<serde_json::Error> for Error {
37 fn from(value: serde_json::Error) -> Self {
38 ErrorKind::from(value).into()
39 }
40}
41
42impl From<wasmtime::Error> for Error {
43 fn from(value: wasmtime::Error) -> Self {
44 ErrorKind::from(value).into()
45 }
46}
47
48#[derive(Debug, Error)]
49#[allow(dead_code)]
50pub(crate) enum ErrorKind {
51 #[error("storage error - {0}")]
54 Db(#[from] borderless_kv_store::Error),
55
56 #[error("encoding error (binary) - {0}")]
58 BinaryEncoding(#[from] postcard::Error),
59
60 #[error("encoding error (json) - {0}")]
62 JsonEncoding(#[from] serde_json::Error),
63
64 #[error("wasmtime error - {0}")]
66 Wasm(#[from] wasmtime::Error),
67
68 #[error("exported function '{func}' has invalid type")]
71 InvalidFuncType { func: &'static str },
72
73 #[error("exported item '{func}' must be a function")]
75 InvalidExport { func: &'static str },
76
77 #[error("module is missing required export '{func}'")]
79 MissingExport { func: &'static str },
80
81 #[error("contract is not instantiated cid={cid}")]
84 MissingContract { cid: ContractId },
85
86 #[error("contract is not instantiated aid={aid}")]
87 MissingAgent { aid: AgentId },
88
89 #[error("contract is revoked and cannot process transactions cid={cid}")]
90 RevokedContract { cid: ContractId },
91
92 #[error("agent is revoked and cannot process transactions aid={aid}")]
93 RevokedAgent { aid: AgentId },
94
95 #[error("introduction id is not for the correct type of entity - agent vs contract mismatch")]
96 InvalidIdType,
97
98 #[error("the entity was already introduced")]
99 DoubleIntroduction,
100
101 #[error("missing required value '{0}' in register")]
104 MissingRegisterValue(&'static str),
105
106 #[error("invalid value in register '{register}' - expected {expected_type}")]
108 InvalidRegisterValue {
109 register: &'static str,
110 expected_type: &'static str,
111 },
112
113 #[error("running entity in VmState is marked 'immutable' - cannot mutate state or storage")]
115 Immutable,
116
117 #[error("no active entity in VmState")]
118 NoActiveEntity,
119
120 #[error("VmState is not initialized with async support")]
121 NoAsync,
122
123 #[error("{0}")]
125 Msg(String),
126}