Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/edda

crates/nornir-flight/src/error.rs

//! The transport-seam error type.

use arrow_flight::error::FlightError;

/// Errors from the [`crate`] transport seam. Deliberately small: the seam is a
/// pipe, so its failures are transport (`tonic`/`arrow-flight`) or a
/// sink/source rejecting a routing key.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// The underlying tonic transport (bind, connect, stream) failed.
    #[error("transport: {0}")]
    Transport(#[from] tonic::transport::Error),

    /// An Arrow Flight encode/decode error (framing, IPC, schema).
    #[error("flight: {0}")]
    Flight(#[from] FlightError),

    /// A tonic status surfaced from a call (e.g. `UNAUTHENTICATED` from the
    /// shared auth interceptor, or `NOT_FOUND` for an unknown ticket).
    #[error("status: {0}")]
    Status(#[from] tonic::Status),

    /// A [`FlightSink`](crate::FlightSink) / [`FlightSource`](crate::FlightSource)
    /// rejected the operation (unknown key, backpressure, closed). Carries a
    /// human-readable reason the server maps onto a `tonic::Status`.
    #[error("sink/source: {0}")]
    Route(String),
}

/// The crate result alias.
pub type Result<T> = std::result::Result<T, Error>;

impl From<Error> for tonic::Status {
    fn from(e: Error) -> Self {
        match e {
            Error::Status(s) => s,
            Error::Route(msg) => tonic::Status::not_found(msg),
            other => tonic::Status::internal(other.to_string()),
        }
    }
}