Mountain/Vine/
Error.rs

1//! # VineError
2//!
3//! Defines the specific, structured error types for all operations within the
4//! Vine gRPC Inter-Process Communication (IPC) system.
5
6#![allow(non_snake_case, non_camel_case_types)]
7
8use std::{
9	net::AddrParseError,
10	sync::{MutexGuard, PoisonError},
11};
12
13use http::uri::InvalidUri;
14use thiserror::Error;
15
16/// A comprehensive error enum for the Vine IPC layer.
17#[derive(Debug, Error)]
18pub enum VineError {
19	/// A gRPC client channel for the specified sidecar could not be found or
20	/// is not ready.
21	#[error("SideCar '{0}' not found or its gRPC client channel is not ready.")]
22	ClientNotConnected(String),
23
24	/// An RPC call to a sidecar failed with a specific gRPC status.
25	#[error("gRPC call failed: {0}")]
26	RPCError(String),
27
28	/// An error occurred while serializing or deserializing a JSON payload.
29	#[error("JSON serialization error for gRPC payload: {0}")]
30	SerializationError(#[from] serde_json::Error),
31
32	/// A low-level error occurred in the `tonic` gRPC transport layer.
33	#[error("Tonic transport error: {0}")]
34	TonicTransportError(#[from] tonic::transport::Error),
35
36	/// A request did not receive a response within the specified timeout.
37	#[error(
38		"Request to sidecar '{SideCarIdentifier}' (method: '{MethodName}') timed out after {TimeoutMilliseconds}ms"
39	)]
40	RequestTimeout { SideCarIdentifier:String, MethodName:String, TimeoutMilliseconds:u64 },
41
42	/// A shared state mutex was "poisoned," indicating a panic.
43	#[error("Internal state lock poisoned: {0}")]
44	InternalLockError(String),
45
46	/// An error occurred from an invalid URI.
47	#[error("Invalid URI: {0}")]
48	InvalidUri(#[from] InvalidUri),
49
50	/// An error occurred while parsing a socket address.
51	#[error("Invalid Socket Address: {0}")]
52	AddressParseError(#[from] AddrParseError),
53}
54
55impl<T> From<PoisonError<MutexGuard<'_, T>>> for VineError {
56	fn from(Error:PoisonError<MutexGuard<'_, T>>) -> Self {
57		VineError::InternalLockError(format!("Shared state lock poisoned: {}", Error))
58	}
59}
60
61impl From<tonic::Status> for VineError {
62	fn from(status:tonic::Status) -> Self { VineError::RPCError(status.to_string()) }
63}