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 provided gRPC server endpoint is invalid.
20    #[error("invalid uri {0}")]
21    InvalidEndpoint(String),
22    /// Indicates that the connection to the server failed.
23    #[error("failed to connect to prover {0}")]
24    ConnectionFailed(#[source] Box<dyn CoreError + Send + Sync + 'static>),
25    /// Custom error variant for errors not covered by the other variants.
26    #[error("{error_msg}")]
27    Other {
28        error_msg: Box<str>,
29        source: Option<Box<dyn CoreError + Send + Sync + 'static>>,
30    },
31}
32
33impl From<RemoteProverClientError> for String {
34    fn from(err: RemoteProverClientError) -> Self {
35        err.to_string()
36    }
37}
38
39impl RemoteProverClientError {
40    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an error
41    /// message.
42    pub fn other(message: impl Into<String>) -> Self {
43        let message: String = message.into();
44        Self::Other { error_msg: message.into(), source: None }
45    }
46
47    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an error
48    /// message and a source error.
49    pub fn other_with_source(
50        message: impl Into<String>,
51        source: impl CoreError + Send + Sync + 'static,
52    ) -> Self {
53        let message: String = message.into();
54        Self::Other {
55            error_msg: message.into(),
56            source: Some(Box::new(source)),
57        }
58    }
59}