1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use thiserror::Error;

/// The RPC Error type.
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
  /// Error during the parsing of an IP address and port.
  #[error(transparent)]
  AddrParseError(#[from] std::net::AddrParseError),

  /// Upstream error from Tonic.
  #[error(transparent)]
  TranportFailure(#[from] tonic::transport::Error),

  /// Upstream error from [wick_rpc].
  #[error(transparent)]
  RpcError(#[from] wick_rpc::Error),

  /// Internal Error.
  #[error("Internal Error: {0}")]
  InternalError(String),

  /// Error used by collections.
  #[error("{0}")]
  CollectionError(String),

  /// Error generated by a collection's components.
  #[error("Component error: {0}")]
  ComponentError(String),

  /// Error sending output to channel.
  #[error("Error sending output to channel")]
  SendError,

  /// General Error.
  #[error("General error: {0}")]
  Other(String),
}

impl From<tokio::task::JoinError> for Error {
  fn from(e: tokio::task::JoinError) -> Self {
    Error::InternalError(format!("Tokio Error: {}", e))
  }
}

impl From<std::io::Error> for Error {
  fn from(e: std::io::Error) -> Self {
    Error::InternalError(format!("IO Error: {}", e))
  }
}

impl From<Box<dyn std::error::Error + Send + Sync>> for Error {
  fn from(e: Box<dyn std::error::Error + Send + Sync>) -> Self {
    Error::CollectionError(e.to_string())
  }
}