use std::net::SocketAddr;
use crate::config::ConfigError;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum GrpcError {
#[error(transparent)]
Config(#[from] ConfigError),
#[error("cannot bind gRPC listener on {addr}: {source}")]
Bind {
addr: SocketAddr,
source: std::io::Error,
},
#[error("cannot build gRPC reflection: {0}")]
Reflection(String),
#[error("cannot set up gRPC TLS: {0}")]
Tls(String),
#[error("gRPC service `{0}` is added twice; each service name must be unique")]
DuplicateService(String),
#[error("the gRPC server cannot start in state `{0}`")]
NotIdle(crate::lifecycle::Lifecycle),
#[error("only one gRPC plugin can use `listener = \"shared\"`; `[{0}]` uses it already")]
SharedListenerTaken(String),
#[error(
"Autumn TLS (`[server.tls]`) in autumn-web {0} does not offer HTTP/2 (ALPN `h2`), so gRPC \
clients cannot connect; autumn-foundation/autumn#2321 fixes this in the next Autumn \
release. Use `listener = \"dedicated\"`, or end TLS at a proxy"
)]
SharedListenerNeedsH2(&'static str),
#[error(
"gRPC client `{0}` is registered twice: two registrations of one type, or registrations in two plugins"
)]
DuplicateClient(String),
#[error(
"gRPC client `{name}` has no endpoint; set `endpoint` in `[{section}.clients.{name}]`, or add `client_double(\"{name}\", ..)`"
)]
ClientWithoutEndpoint {
name: String,
section: String,
},
#[error("gRPC client double `{0}` has no client; add `GrpcPlugin::client(\"{0}\", ..)`")]
DoubleWithoutClient(String),
#[error("cannot set up gRPC client `{name}`: {message}")]
ClientSetup {
name: String,
message: String,
},
#[error("the gRPC server is already started")]
AlreadyStarted,
}