1use serde_json::Value;
2use wick_interface_types::Type;
3
4use crate::PacketError;
5
6#[derive(Debug, thiserror::Error, PartialEq, Clone)]
8#[non_exhaustive]
9pub enum Error {
10 #[error("No stream found for port '{0}'")]
12 PortMissing(String),
13
14 #[error("Error deserializing payload '{}': {}",.as_json,.error)]
16 Decode { as_json: String, error: String },
17
18 #[error("Error JSON-ifying payload: {0}")]
20 Jsonify(String),
21
22 #[error("Error communicating over a stream or channel: {0}")]
24 Channel(String),
25
26 #[error("{0}")]
28 Component(String),
29
30 #[error("No data in payload")]
32 NoData,
33
34 #[error("{}", .0.msg())]
36 PayloadError(PacketError),
37
38 #[error("Got a Done signal in an unexpected context.")]
40 UnexpectedDone,
41
42 #[error("Could not retrieve configuration item '{0}'")]
44 ContextKey(String),
45
46 #[error("Can only convert JSON Objects to a operation and component configuration, got '{0}'")]
48 BadJson(Value),
49
50 #[error("Could not retrieve a complete set of packets. Stream '{0}' failed to provide a packet: '{1}'")]
52 StreamMapError(String , String ),
53
54 #[error("Could not retrieve a complete set of packets. Stream '{0}' completed or failed before providing a packet.")]
56 StreamMapMissing(String ),
57
58 #[error("Configuration provided for component '{0}' does not match expected signature, {1}")]
59 Signature(String, String),
60
61 #[cfg(feature = "datetime")]
62 #[error("Error parsing date '{0}', date must be an RFC 3339 formatted string")]
63 ParseDate(String),
64
65 #[cfg(feature = "datetime")]
66 #[error("Error parsing date '{0}', date must be milliseconds from the UNIX epoch")]
67 ParseDateMillis(u64),
68
69 #[error("Could not coerce value {value} to a {desired}")]
70 Coersion { value: Value, desired: Type },
71}
72
73impl Error {
74 pub fn component_error<T: Into<String>>(msg: T) -> Self {
75 Self::Component(msg.into())
76 }
77}
78
79impl From<wasmrs_rx::Error> for Error {
80 fn from(value: wasmrs_rx::Error) -> Self {
81 Self::Channel(value.to_string())
82 }
83}
84
85impl From<Box<dyn std::error::Error>> for Error {
86 fn from(value: Box<dyn std::error::Error>) -> Self {
87 Self::Component(value.to_string())
88 }
89}
90
91#[derive(thiserror::Error, Debug)]
92#[non_exhaustive]
93pub enum ParseError {
95 #[error("Invalid scheme {0}")]
97 Scheme(String),
98 #[error("Missing path")]
100 MissingPath,
101 #[error("Missing authority/host")]
103 Authority,
104 #[error("Invalid authority/host '{0}', missing separator '.'")]
106 InvalidAuthority(String),
107 #[error("Invalid authority/host kind '{0}'")]
109 InvalidAuthorityKind(String),
110 #[error("{0}")]
112 Parse(url::ParseError),
113 #[error(transparent)]
115 Conversion(Box<dyn std::error::Error + Send + Sync>),
116}