wick_component_cli/
error.rs

1use thiserror::Error;
2use wick_interface_types::Type;
3
4#[derive(Error, Debug)]
5/// The error returned by the collection CLI.
6#[non_exhaustive]
7pub enum CliError {
8  #[error(transparent)]
9  #[cfg(any(feature = "grpc", feature = "mesh"))]
10  /// An upstream error from [wick_rpc].
11  RpcError(#[from] wick_rpc::Error),
12
13  #[error(transparent)]
14  /// An error parsing an IP address.
15  IpAddrError(#[from] std::net::AddrParseError),
16
17  #[error(transparent)]
18  /// An IO error binding to a port or similar.
19  IOError(#[from] std::io::Error),
20
21  #[cfg(feature = "grpc")]
22  #[error(transparent)]
23  /// Error related to configuration or asset loading.
24  Config(#[from] wick_config::AssetError),
25
26  #[error(transparent)]
27  #[cfg(feature = "grpc")]
28  /// An upstream error from [tonic].
29  TransportError(#[from] tonic::transport::Error),
30
31  #[error(transparent)]
32  /// An internal error running asynchronous jobs.
33  JoinError(#[from] tokio::task::JoinError),
34
35  #[error("invalid argument: {0}")]
36  /// Thrown when the CLI received an invalid argument to pass to an invocation.
37  InvalidArgument(String),
38
39  #[error("Input '{0}' not found in signature")]
40  /// Thrown when parsed input name was not found on the target operation.
41  InvalidInput(String),
42
43  #[error("{0}")]
44  /// A general configuration error.
45  Configuration(String),
46
47  #[error("Could not convert data '{data}' to a format suitable for port {port}'s type {ty}")]
48  /// Could not convert passed argument to a suitable intermediary format.
49  Encoding {
50    /// The data that could not be converted.
51    data: String,
52    /// The port that the data was being passed to.
53    port: String,
54    /// The type of the port.
55    ty: Type,
56  },
57
58  #[error("Found argument '{0}' which requires a value but no value was supplied")]
59  /// Dangling arguments (e.g. --arg instead of --arg value or --arg=value)
60  MissingArgumentValue(String),
61}
62
63impl CliError {
64  pub(crate) fn encoding<T: Into<String>, D: Into<String>>(port: T, data: D, ty: Type) -> Self {
65    Self::Encoding {
66      data: data.into(),
67      port: port.into(),
68      ty,
69    }
70  }
71}