Skip to main content

autumn_plugin_pingora/
error.rs

1//! Errors that stop the proxy from starting.
2
3use std::net::SocketAddr;
4
5use crate::config::ConfigError;
6
7/// A startup failure. Boot stops. The plugin never falls back silently.
8/// Autumn shows the message in its boot error.
9#[derive(Debug, thiserror::Error)]
10#[non_exhaustive]
11pub enum PingoraError {
12    /// The configuration is not valid.
13    #[error(transparent)]
14    Config(#[from] ConfigError),
15    /// The listener cannot bind.
16    #[error("cannot bind the proxy listener on {addr}: {source}")]
17    Bind {
18        /// The address.
19        addr: SocketAddr,
20        /// The cause.
21        source: std::io::Error,
22    },
23    /// An upstream address does not resolve.
24    #[error("route `{route}`: cannot resolve upstream \"{upstream}\": {reason}")]
25    Resolve {
26        /// The route name.
27        route: String,
28        /// The upstream as configured.
29        upstream: String,
30        /// The cause.
31        reason: String,
32    },
33    /// The Autumn app address does not resolve.
34    #[error("cannot resolve the Autumn app address \"{0}\" for `fallback = \"app\"`")]
35    AppAddress(String),
36    /// The fallback target serves TLS. v0.1 has no upstream TLS.
37    #[error(
38        "`fallback = \"app\"` needs a plain HTTP app. `[server.tls]` is set. Put a TLS terminator in front of the proxy, or set `fallback = \"none\"`"
39    )]
40    FallbackTls,
41    /// The proxy would send unmatched requests to itself.
42    #[error(
43        "the proxy address is the Autumn app address {0}. With `fallback = \"app\"`, requests would go in a loop. Set a different `bind`"
44    )]
45    FallbackLoop(SocketAddr),
46    /// The startup hook ran again, or the proxy stopped before it started.
47    #[error("the proxy started or stopped before; it can start one time only")]
48    AlreadyStarted,
49}