1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Error types for the Eryx sandbox.
use crate::callback::CallbackError;
/// The main error type for Eryx operations.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Error during sandbox initialization.
#[error("initialization failed: {0}")]
Initialization(String),
/// Error during WASM engine creation.
#[error("wasm engine error: {0}")]
WasmEngine(String),
/// Error during WASM component loading or instantiation.
#[error("wasm component error: {0}")]
WasmComponent(#[from] wasmtime::Error),
/// Error during Python execution.
#[error("execution failed: {0}")]
Execution(String),
/// A callback error occurred during execution.
#[error("callback error: {0}")]
Callback(#[from] CallbackError),
/// Resource limit exceeded.
#[error("resource limit exceeded: {0}")]
ResourceLimit(String),
/// Execution timed out.
#[error("execution timed out after {0:?}")]
Timeout(std::time::Duration),
/// Execution ran out of fuel (instruction limit exceeded).
#[error("execution ran out of fuel after {consumed} instructions (limit: {limit})")]
FuelExhausted {
/// Number of instructions consumed before exhaustion.
consumed: u64,
/// The fuel limit that was set.
limit: u64,
},
/// Serialization/deserialization error.
#[error("serialization error: {0}")]
Serialization(String),
/// Python stdlib not found during auto-detection.
///
/// Use [`SandboxBuilder::with_python_stdlib()`](crate::SandboxBuilder::with_python_stdlib)
/// to specify the stdlib path explicitly, or enable the `embedded` feature and use
/// [`Sandbox::embedded()`](crate::Sandbox::embedded).
#[error(
"Python stdlib not found. Set ERYX_PYTHON_STDLIB, use with_python_stdlib(), or use Sandbox::embedded()"
)]
MissingPythonStdlib,
/// State snapshot error.
#[error("snapshot error: {0}")]
Snapshot(String),
/// Execution was cancelled.
#[error("execution cancelled")]
Cancelled,
/// I/O error.
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Self::Serialization(err.to_string())
}
}