miden_remote_prover_client/
lib.rs

1#![no_std]
2// We allow unused imports here in order because this `macro_use` only makes sense for code
3// generated by prost under certain circumstances (when `tx-prover` is enabled and the environment
4// is not wasm)
5#![allow(unused_imports)]
6#[macro_use]
7extern crate alloc;
8
9use alloc::boxed::Box;
10use alloc::string::{String, ToString};
11use core::error::Error as CoreError;
12
13#[cfg(feature = "std")]
14extern crate std;
15
16use thiserror::Error;
17
18pub mod remote_prover;
19
20/// ERRORS
21/// ===============================================================================================
22
23#[derive(Debug, Error)]
24pub enum RemoteProverClientError {
25    /// Indicates that the provided gRPC server endpoint is invalid.
26    #[error("invalid uri {0}")]
27    InvalidEndpoint(String),
28    #[error("failed to connect to prover {0}")]
29    /// Indicates that the connection to the server failed.
30    ConnectionFailed(#[source] Box<dyn CoreError + Send + Sync + 'static>),
31    /// Custom error variant for errors not covered by the other variants.
32    #[error("{error_msg}")]
33    Other {
34        error_msg: Box<str>,
35        // thiserror will return this when calling `Error::source` on
36        // `RemoteProverClientError`.
37        source: Option<Box<dyn CoreError + Send + Sync + 'static>>,
38    },
39}
40
41impl From<RemoteProverClientError> for String {
42    fn from(err: RemoteProverClientError) -> Self {
43        err.to_string()
44    }
45}
46
47impl RemoteProverClientError {
48    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an
49    /// error message.
50    pub fn other(message: impl Into<String>) -> Self {
51        let message: String = message.into();
52        Self::Other { error_msg: message.into(), source: None }
53    }
54
55    /// Creates a custom error using the [`RemoteProverClientError::Other`] variant from an
56    /// error message and a source error.
57    pub fn other_with_source(
58        message: impl Into<String>,
59        source: impl CoreError + Send + Sync + 'static,
60    ) -> Self {
61        let message: String = message.into();
62        Self::Other {
63            error_msg: message.into(),
64            source: Some(Box::new(source)),
65        }
66    }
67}