Skip to main content

zlayer_gcs/
error.rs

1//! Error type for the GCS bridge.
2//!
3//! All public surface returns [`GcsResult<T>`]; transport, framing, protocol
4//! negotiation, and RPC dispatch all funnel their failure modes through the
5//! single [`GcsError`] enum so callers can match on the failure class without
6//! caring which sub-layer produced it.
7
8use thiserror::Error;
9
10/// Errors that can occur while talking to a UVM's Guest Compute Service.
11#[derive(Debug, Error)]
12#[non_exhaustive]
13pub enum GcsError {
14    /// Underlying I/O failure on the hvsock transport (read/write/connect).
15    #[error("gcs i/o: {0}")]
16    Io(#[from] std::io::Error),
17
18    /// JSON encode/decode failure on a GCS protocol message payload.
19    #[error("gcs json: {0}")]
20    Json(#[from] serde_json::Error),
21
22    /// Hyper-V socket (`AF_HYPERV`) setup or address resolution failure.
23    #[error("hvsock: {0}")]
24    Hvsock(String),
25
26    /// Generic protocol-layer violation — unexpected message type, bad
27    /// sequence number, frame length out of range, etc.
28    #[error("protocol: {0}")]
29    Protocol(String),
30
31    /// Capability/version negotiation with the in-guest GCS failed.
32    #[error("negotiation: {0}")]
33    Negotiation(String),
34
35    /// An RPC or read/write operation exceeded its deadline.
36    #[error("operation timed out")]
37    Timeout,
38
39    /// The bridge connection has been closed (cleanly or by the peer).
40    #[error("bridge closed")]
41    Closed,
42}
43
44/// Convenience alias for results returned by the GCS bridge.
45pub type GcsResult<T> = Result<T, GcsError>;