avm_server/errors.rs
1/*
2 * AquaVM Workflow Engine
3 *
4 * Copyright (C) 2024 Fluence DAO
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation version 3 of the
9 * License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20pub use avm_interface::CallSeDeErrors;
21use avm_interface::ErrorAVMOutcome;
22use marine::IValue;
23use marine::MarineError;
24
25use serde_json::Error as SerdeError;
26use thiserror::Error as ThisError;
27
28use std::io::Error as IOError;
29use std::path::PathBuf;
30
31#[derive(Debug, ThisError)]
32pub enum AVMError<E> {
33 /// This error contains interpreter outcome in case when execution failed on the interpreter
34 /// side. A host should match on this error type explicitly to save provided data.
35 #[error("interpreter failed with: {0:?}")]
36 InterpreterFailed(ErrorAVMOutcome),
37
38 /// This errors are encountered from an AVM runner.
39 #[error(transparent)]
40 RunnerError(RunnerError),
41
42 /// This errors are encountered from a data store object.
43 #[error(transparent)]
44 DataStoreError(#[from] E),
45
46 /// This errors are encountered from serialization of data tracked during an anomaly.
47 #[error(transparent)]
48 AnomalyDataSeError(SerdeError),
49}
50
51#[derive(Debug, ThisError)]
52pub enum RunnerError {
53 /// This errors are encountered from FaaS.
54 #[error(transparent)]
55 MarineError(#[from] MarineError),
56
57 /// Specified path to AIR interpreter .wasm file was invalid
58 #[error("path to AIR interpreter .wasm ({invalid_path:?}) is invalid: {reason}; IO Error: {io_error:?}")]
59 InvalidAIRPath {
60 invalid_path: PathBuf,
61 io_error: Option<IOError>,
62 reason: &'static str,
63 },
64
65 /// AIR interpreter result deserialization errors.
66 #[error("{0}")]
67 InterpreterResultDeError(String),
68
69 /// Marine call returns Vec<IValue> to support multi-value in a future,
70 /// but actually now it could return empty vec or a vec with one value.
71 /// This error is encountered when it returns vec with not a one value.
72 #[error("result `{0:?}` returned from Marine should contain only one element")]
73 IncorrectInterpreterResult(Vec<IValue>),
74
75 /// This errors are encountered from an call results/params se/de.
76 #[error(transparent)]
77 CallSeDeErrors(#[from] CallSeDeErrors),
78
79 /// Invalid secret key.
80 #[error(transparent)]
81 KeyError(eyre::Error),
82
83 /// Errors from auxiliary calls.
84 #[error("{0}")]
85 Aux(String),
86}