Skip to main content

inferlab_proxy/
error.rs

1use std::fmt;
2
3/// Bounded-context error for the built-in proxy crate's lifecycle and setup
4/// path: building the Tokio runtime, validating proxy configuration, binding the
5/// listener on the configured host and port, running the HTTP server, and
6/// discovering the upstream prefill/decode backends it fronts. Each variant
7/// preserves the kind of failure
8/// plus the actionable detail, following the hand-rolled `ConfigError`
9/// convention used by Inferlab rather than collapsing every failure into one
10/// opaque string at the library boundary.
11///
12/// This is distinct from [`crate::core::ProxyHttpError`], the per-request error
13/// returned by the HTTP handlers (which carries an HTTP status and renders an
14/// `IntoResponse`); `ProxyError` covers the process lifecycle that stands the
15/// proxy up before any request is served.
16#[derive(Clone, Debug, Eq, PartialEq)]
17pub enum ProxyError {
18    /// A filesystem/network I/O operation failed (e.g. binding the listener or
19    /// running the server loop).
20    Io { message: String },
21    /// An external tool or upstream backend interaction failed during setup
22    /// (e.g. discovering the prefill engines this proxy fronts).
23    ExternalTool { message: String },
24    /// Proxy configuration failed validation (e.g. no prefill or decode
25    /// endpoints were provided).
26    Invalid { message: String },
27    /// A runtime/process lifecycle step failed (e.g. building the Tokio
28    /// runtime).
29    Lifecycle { message: String },
30}
31
32impl fmt::Display for ProxyError {
33    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
34        match self {
35            Self::Io { message }
36            | Self::ExternalTool { message }
37            | Self::Invalid { message }
38            | Self::Lifecycle { message } => formatter.write_str(message),
39        }
40    }
41}
42
43impl std::error::Error for ProxyError {}