Skip to main content

dig_rpc/
error.rs

1//! Server-level errors (NOT per-request — per-request errors are JSON-RPC
2//! envelopes defined in `dig-rpc-types`).
3
4use std::net::SocketAddr;
5use std::sync::Arc;
6
7use thiserror::Error;
8
9/// All server-level failure modes.
10///
11/// Per-request errors are returned as `JsonRpcError` envelopes from
12/// [`crate::dispatch::dispatch_envelope`]; those use
13/// [`dig_rpc_types::errors::ErrorCode`] for wire compatibility. The errors
14/// here are strictly for `RpcServer` startup and fatal runtime failures.
15#[derive(Error, Debug, Clone)]
16pub enum RpcServerError {
17    /// Binding the TCP / TLS listener on `addr` failed.
18    #[error("failed to bind {addr}: {source}")]
19    BindFailed {
20        /// The address the server tried to bind.
21        addr: SocketAddr,
22        /// The underlying I/O error.
23        #[source]
24        source: Arc<std::io::Error>,
25    },
26
27    /// TLS configuration could not be loaded (cert file missing, bad PEM,
28    /// expired cert, mismatched key).
29    #[error("TLS setup failed: {0}")]
30    TlsSetup(#[source] Arc<anyhow::Error>),
31
32    /// Catch-all unrecoverable server error.
33    #[error("fatal server error: {0}")]
34    Fatal(#[source] Arc<anyhow::Error>),
35}
36
37impl From<std::io::Error> for RpcServerError {
38    fn from(e: std::io::Error) -> Self {
39        RpcServerError::Fatal(Arc::new(anyhow::anyhow!(e)))
40    }
41}