stemedb/crates/stemedb-rpc/src/error.rs
jordan 2b0923f20e feat: Distributed replication foundation (Phase 6A) - HLC, Merkle trees, CRDT stores, sync protocol
- Add Hybrid Logical Clock (HLC) for causality tracking across nodes
- Implement Merkle tree for efficient diff/sync with BLAKE3 hashing
- Add CRDT-aware stores for assertions and votes with vector clocks
- Create stemedb-sync crate with anti-entropy and gossip protocols
- Add stemedb-rpc crate with gRPC sync service (proto definitions)
- Implement SupersessionChain for tracking assertion lifecycles
- Add Aphoria application for code analysis/reporting
- Add battery11 replication test scaffolding
- Fix .gitignore to exclude nested target directories

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 19:31:54 -07:00

66 lines
1.9 KiB
Rust

//! Error types for the RPC layer.
//!
//! Provides a unified error type for client/server operations,
//! with automatic conversions from underlying transport errors.
use thiserror::Error;
/// Errors that can occur during RPC operations.
#[derive(Debug, Error)]
pub enum RpcError {
/// Connection failed or was refused.
#[error("Connection error: {0}")]
Connection(String),
/// Request timed out.
#[error("Request timeout: {0}")]
Timeout(String),
/// Server returned an error status.
#[error("Server error: {0}")]
Server(String),
/// Failed to serialize/deserialize data.
#[error("Serialization error: {0}")]
Serialization(String),
/// Invalid request or response data.
#[error("Invalid data: {0}")]
InvalidData(String),
/// Maximum retry attempts exceeded.
#[error("Retry limit exceeded after {attempts} attempts: {last_error}")]
RetryExhausted {
/// Number of attempts made.
attempts: u32,
/// The last error encountered.
last_error: String,
},
/// Internal transport error.
#[error("Transport error: {0}")]
Transport(String),
}
impl From<tonic::Status> for RpcError {
fn from(status: tonic::Status) -> Self {
match status.code() {
tonic::Code::Unavailable | tonic::Code::Unknown => {
RpcError::Connection(status.message().to_string())
}
tonic::Code::DeadlineExceeded => RpcError::Timeout(status.message().to_string()),
tonic::Code::InvalidArgument => RpcError::InvalidData(status.message().to_string()),
_ => RpcError::Server(format!("{}: {}", status.code(), status.message())),
}
}
}
impl From<tonic::transport::Error> for RpcError {
fn from(err: tonic::transport::Error) -> Self {
RpcError::Connection(err.to_string())
}
}
/// Result type for RPC operations.
pub type Result<T> = std::result::Result<T, RpcError>;