Skip to main content

miden_client/remote_prover/
mod.rs

1use alloc::boxed::Box;
2use alloc::string::{String, ToString};
3use core::error::Error as CoreError;
4
5use thiserror::Error;
6
7mod api_client;
8mod generated;
9mod tx_prover;
10
11pub use tx_prover::RemoteTransactionProver;
12
13// ERRORS
14// ================================================================================================
15
16/// Errors that can occur when communicating with a remote prover.
17#[derive(Debug, Error)]
18pub enum RemoteProverClientError {
19    /// Indicates that the connection to the server failed.
20    #[error("failed to connect to prover {0}")]
21    ConnectionFailed(#[source] Box<dyn CoreError + Send + Sync + 'static>),
22    /// Custom error variant for errors not covered by the other variants.
23    #[error("{error_msg}")]
24    Other {
25        error_msg: Box<str>,
26        source: Option<Box<dyn CoreError + Send + Sync + 'static>>,
27    },
28}
29
30impl From<RemoteProverClientError> for String {
31    fn from(err: RemoteProverClientError) -> Self {
32        err.to_string()
33    }
34}
35
36impl RemoteProverClientError {
37    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an error
38    /// message.
39    pub fn other(message: impl Into<String>) -> Self {
40        let message: String = message.into();
41        Self::Other { error_msg: message.into(), source: None }
42    }
43
44    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an error
45    /// message and a source error.
46    pub fn other_with_source(
47        message: impl Into<String>,
48        source: impl CoreError + Send + Sync + 'static,
49    ) -> Self {
50        let message: String = message.into();
51        Self::Other {
52            error_msg: message.into(),
53            source: Some(Box::new(source)),
54        }
55    }
56}