Skip to main content

miden_testing/tx_context/
errors.rs

1use alloc::string::ToString;
2
3use miden_processor::ExecutionError;
4use miden_protocol::assembly::diagnostics::reporting::PrintDiagnostic;
5use thiserror::Error;
6
7// EXECUTION ERROR
8// ================================================================================================
9
10/// A newtype wrapper around [`ExecutionError`] that provides better error messages
11/// by using [`PrintDiagnostic`] for display formatting.
12#[derive(Debug, Error)]
13#[error("{}", PrintDiagnostic::new(.0).to_string())]
14pub struct ExecError(pub ExecutionError);
15
16impl ExecError {
17    /// Creates a new `ExecError` from an `ExecutionError`.
18    pub fn new(error: ExecutionError) -> Self {
19        Self(error)
20    }
21
22    /// Returns a reference to the inner `ExecutionError`.
23    pub fn as_execution_error(&self) -> &ExecutionError {
24        &self.0
25    }
26
27    /// Consumes `ExecError` and returns the inner `ExecutionError`.
28    pub fn into_execution_error(self) -> ExecutionError {
29        self.0
30    }
31}