1use std::fmt::Debug;
2use thiserror::Error as ThisError;
3use tokio::sync::mpsc::error::SendError;
4
5use tonic::transport::Error as TonicError;
6
7use http::uri::InvalidUri;
8
9pub fn into_status(err: Error) -> tonic::Status {
10 tonic::Status::unknown(format!("{}", err))
11}
12
13#[derive(Debug, ThisError)]
14pub enum Error {
15 #[error("No ports were available to bind the plugin's gRPC server to.")]
16 NoTCPPortAvailable,
17 #[error("This executable is meant to be a go-plugin to other processes. Do not run this directly. The Magic Handshake failed.")]
18 GRPCHandshakeMagicCookieValueMismatch,
19 #[error("The requested ServiceId {0} does not exist and timed out waiting for it.")]
20 ServiceIdDoesNotExist(u32),
21 #[error("Error with IO: {0}")]
22 Io(#[from] std::io::Error),
23 #[error("Error with tonic (gRPC) transport: {0}")]
24 TonicTransport(#[from] TonicError),
25 #[error("Error parsing string into a network address: {0}")]
26 AddrParser(#[from] std::net::AddrParseError),
27 #[error("Error sending on a mpsc channel: {0}")]
28 Send(String),
29 #[error("Invalid Uri: {0}")]
30 InvalidUri(#[from] InvalidUri),
31 #[error("Service endpoint type unknown: {0}")]
32 NetworkTypeUnknown(String),
33 #[error(transparent)]
34 Other(#[from] anyhow::Error),
35}
36
37impl<T> From<SendError<T>> for Error {
38 fn from(_err: SendError<T>) -> Self {
39 Self::Send(format!(
40 "unable to send {} on a mpsc channel",
41 std::any::type_name::<T>()
42 ))
43 }
44}