Skip to main content

autumn_plugin_grpc/
error.rs

1//! Errors that stop the plugin from starting.
2
3use std::net::SocketAddr;
4
5use crate::config::ConfigError;
6
7/// A startup failure. Each one aborts boot.
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum GrpcError {
11    /// The configuration is not valid.
12    #[error(transparent)]
13    Config(#[from] ConfigError),
14    /// The listener could not bind.
15    #[error("cannot bind gRPC listener on {addr}: {source}")]
16    Bind {
17        /// The address from `bind`.
18        addr: SocketAddr,
19        /// The OS error.
20        source: std::io::Error,
21    },
22    /// A reflection descriptor set is not valid.
23    #[error("cannot build gRPC reflection: {0}")]
24    Reflection(String),
25    /// TLS could not be set up.
26    #[error("cannot set up gRPC TLS: {0}")]
27    Tls(String),
28    /// Two services have the same name, or a user service has the name of
29    /// a plugin service (health or reflection).
30    #[error("gRPC service `{0}` is added twice; each service name must be unique")]
31    DuplicateService(String),
32    /// The server is not in `Idle`: a shutdown came before or during start.
33    #[error("the gRPC server cannot start in state `{0}`")]
34    NotIdle(crate::lifecycle::Lifecycle),
35    /// Another plugin (its config section) uses the shared listener.
36    #[error("only one gRPC plugin can use `listener = \"shared\"`; `[{0}]` uses it already")]
37    SharedListenerTaken(String),
38    /// Autumn's TLS listener does not offer HTTP/2 (ALPN `h2`).
39    #[error(
40        "Autumn TLS (`[server.tls]`) in autumn-web {0} does not offer HTTP/2 (ALPN `h2`), so gRPC \
41         clients cannot connect; autumn-foundation/autumn#2321 fixes this in the next Autumn \
42         release. Use `listener = \"dedicated\"`, or end TLS at a proxy"
43    )]
44    SharedListenerNeedsH2(&'static str),
45    /// Two registrations use one client name: with one type in one
46    /// plugin, or in two plugins.
47    #[error(
48        "gRPC client `{0}` is registered twice: two registrations of one type, or registrations in two plugins"
49    )]
50    DuplicateClient(String),
51    /// A registered client has no endpoint and no test double.
52    #[error(
53        "gRPC client `{name}` has no endpoint; set `endpoint` in `[{section}.clients.{name}]`, or add `client_double(\"{name}\", ..)`"
54    )]
55    ClientWithoutEndpoint {
56        /// The client name.
57        name: String,
58        /// The config section of the plugin.
59        section: String,
60    },
61    /// A test double names a client that is not registered.
62    #[error("gRPC client double `{0}` has no client; add `GrpcPlugin::client(\"{0}\", ..)`")]
63    DoubleWithoutClient(String),
64    /// A client channel could not be set up (for example, a TLS file).
65    #[error("cannot set up gRPC client `{name}`: {message}")]
66    ClientSetup {
67        /// The client name.
68        name: String,
69        /// The problem.
70        message: String,
71    },
72    /// The startup hook ran twice.
73    #[error("the gRPC server is already started")]
74    AlreadyStarted,
75}