use super::super::problem::*;
impl From<Problem> for wasmtime::Error {
fn from(problem: Problem) -> Self {
if !problem.causes.is_empty() {
let mut causes = problem.into_iter().rev();
let root_cause = causes.next().expect("root cause");
let mut wasmtime_error = wasmtime::Error::from_boxed(root_cause.error);
for cause in causes {
wasmtime_error = wasmtime_error.context(cause.error);
}
wasmtime_error
} else {
problem.into_error().into()
}
}
}
pub trait WasmtimeIntoProblem {
fn into_problem(self) -> Problem;
}
impl WasmtimeIntoProblem for wasmtime::Error {
#[track_caller]
fn into_problem(self) -> Problem {
Problem::new(self.into())
}
}
pub trait WasmtimeIntoProblemResult<OkT> {
fn into_problem(self) -> Result<OkT, Problem>;
}
impl<OkT> WasmtimeIntoProblemResult<OkT> for wasmtime::Result<OkT> {
#[track_caller]
fn into_problem(self) -> Result<OkT, Problem> {
match self {
Ok(ok) => Ok(ok),
Err(error) => Err(error.into_problem()),
}
}
}