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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use thiserror::Error;
use wick_interface_types::Type;

#[derive(Error, Debug)]
/// The error returned by the collection CLI.
#[non_exhaustive]
pub enum CliError {
  #[error(transparent)]
  #[cfg(any(feature = "grpc", feature = "mesh"))]
  /// An upstream error from [wick_rpc].
  RpcError(#[from] wick_rpc::Error),

  #[error(transparent)]
  /// An error parsing an IP address.
  IpAddrError(#[from] std::net::AddrParseError),

  #[error(transparent)]
  /// An IO error binding to a port or similar.
  IOError(#[from] std::io::Error),

  #[cfg(feature = "grpc")]
  #[error(transparent)]
  /// Error related to configuration or asset loading.
  Config(#[from] wick_config::AssetError),

  #[error(transparent)]
  #[cfg(feature = "grpc")]
  /// An upstream error from [tonic].
  TransportError(#[from] tonic::transport::Error),

  #[error(transparent)]
  /// An internal error running asynchronous jobs.
  JoinError(#[from] tokio::task::JoinError),

  #[error("invalid argument: {0}")]
  /// Thrown when the CLI received an invalid argument to pass to an invocation.
  InvalidArgument(String),

  #[error("Input '{0}' not found in signature")]
  /// Thrown when parsed input name was not found on the target operation.
  InvalidInput(String),

  #[error("{0}")]
  /// A general configuration error.
  Configuration(String),

  #[error("Could not convert data '{data}' to a format suitable for port {port}'s type {ty}")]
  /// Could not convert passed argument to a suitable intermediary format.
  Encoding {
    /// The data that could not be converted.
    data: String,
    /// The port that the data was being passed to.
    port: String,
    /// The type of the port.
    ty: Type,
  },

  #[error("Found argument '{0}' which requires a value but no value was supplied")]
  /// Dangling arguments (e.g. --arg instead of --arg value or --arg=value)
  MissingArgumentValue(String),
}

impl CliError {
  pub(crate) fn encoding<T: Into<String>, D: Into<String>>(port: T, data: D, ty: Type) -> Self {
    Self::Encoding {
      data: data.into(),
      port: port.into(),
      ty,
    }
  }
}