sacn_unofficial/error.rs
1// Copyright 2020 sacn Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7//
8// This file was created as part of a University of St Andrews Computer Science BSC Senior Honours Dissertation Project.
9
10/// The errors used within the SacnLibrary. The ErrorKind subsection of this within the documentation contains details of all the errors.
11///
12/// Errors from external sources are wrapped within this error-chain.
13///
14/// Io errors from std::io::Error are wrapped within Io(::std::io::Error)
15///
16/// String errors from std::str::Utf8Error are wrapped within Str(::std::str::Utf8Error)
17///
18/// Uuid errors from uuid::ParseError are wrapped within Uuid(uuid::ParseError)
19///
20///
21/// ParsePack related errors come within their own family wrapped inside this error to allow easy matching (can just match for SacnParsePackError rather than a specific).
22///
23/// SacnParsePackError(sacn_parse_pack_error::Error, sacn_parse_pack_error::ErrorKind)
24///
25/// Uses the error-chain crate to allow errors to allow more informative backtraces through error chaining.
26/// https://docs.rs/error-chain/0.12.2/error_chain/
27pub mod errors {
28 use sacn_parse_pack_error::sacn_parse_pack_error;
29
30 /// UUID library used to handle the UUID's used in the CID fields, used here so that error can include the cid in messages.
31 use uuid::Uuid;
32
33 error_chain! {
34 foreign_links {
35 Io(::std::io::Error); // Allow IO errors to be used with the error-chain system.
36 Str(::std::str::Utf8Error); // Allow standard string library errors to be used with the error-chain system.
37 Uuid(uuid::ParseError); // Allow UUID library to be used with error-chain system.
38 }
39
40 links {
41 // All parse/pack errors live within the same chain ('family') of errors as described in sacn_parse_packet_error.
42 SacnParsePackError(sacn_parse_pack_error::Error, sacn_parse_pack_error::ErrorKind);
43 }
44
45 errors {
46 /// Returned to indicate that an invalid or malformed source name was used.
47 ///
48 /// # Arguments
49 /// msg: A string describing why the source name is malformed.
50 ///
51 MalformedSourceName(msg: String) {
52 description("The given source name was malformed and couldn't be used"),
53 display("The given source name was malformed and couldn't be used, msg: {}", msg)
54 }
55
56 /// Attempted to perform an action using a priority value that is invalid. For example sending with a priority > 200.
57 /// This is distinct from the SacnParsePackError(ParseInvalidPriority) as it is for a local use of an invalid priority
58 /// rather than receiving an invalid priority from another source.
59 ///
60 /// # Arguments
61 /// msg: A string describing why the priority is invalid.
62 ///
63 InvalidPriority(msg: String) {
64 description("Attempted to perform an action using a priority value that is invalid"),
65 display("Attempted to perform an action using a priority value that is invalid, msg: {}", msg)
66 }
67
68 /// Used to indicate that the limit for the number of supported sources has been reached.
69 /// This is based on unique CID values.
70 /// as per ANSI E1.31-2018 Section 6.2.3.3.
71 ///
72 /// # Arguments
73 /// msg: A string describing why the sources exceeded error was returned.
74 ///
75 SourcesExceededError(msg: String) {
76 description("Limit for the number of supported sources has been reached"),
77 display("Limit for the number of supported sources has been reached, msg: {}", msg)
78 }
79
80 /// A source was discovered by a receiver with the announce_discovery_flag set to true.
81 ///
82 /// # Arguments
83 /// source_name: The name of the source discovered.
84 ///
85 SourceDiscovered(source_name: String) {
86 description("A source was discovered by a receiver with the announce_discovery_flag set to true"),
87 display("A source was discovered by a receiver with the announce_discovery_flag set to true, source name: {}", source_name)
88 }
89
90 /// Attempted to exceed the capacity of a single universe (packet::UNIVERSE_CHANNEL_CAPACITY).
91 ///
92 /// # Arguments
93 /// msg: A string describing why/how the universe capacity was exceeded.
94 ///
95 ExceedUniverseCapacity(msg: String) {
96 description("Attempted to exceed the capacity of a single universe"),
97 display("Attempted to exceed the capacity of a single universe, msg: {}", msg)
98 }
99
100 /// Attempted to use illegal universe, outwith allowed range of [E131_MIN_MULTICAST_UNIVERSE, E131_MAX_MULTICAST_UNIVERSE]
101 /// + E131_DISCOVERY_UNIVERSE inclusive
102 ///
103 /// # Arguments
104 /// msg: A string describing why/how the universe is an illegal universe.
105 ///
106 IllegalUniverse(msg: String) {
107 description("Attempted to use illegal universe, outwith allowed range of [E131_MIN_MULTICAST_UNIVERSE
108 - E131_MAX_MULTICAST_UNIVERSE] + E131_DISCOVERY_UNIVERSE inclusive"),
109 display("illegal universe used, outwith allowed range, msg: {}", msg)
110 }
111
112 /// Attempted to use a universe that wasn't first registered for use.
113 /// To send from a universe with a sender it must first be registered. This allows universe discovery adverts to include the universe.
114 ///
115 /// # Arguments
116 /// msg: A string describing why the error was returned.
117 ///
118 UniverseNotRegistered(msg: String) {
119 description("Attempted to use a universe that wasn't first registered for use"),
120 display("Attempted to use a universe that wasn't first registered for use, msg: {}", msg)
121 }
122
123 /// Ip version (ipv4 or ipv6) used when the other is expected.
124 ///
125 /// # Arguments
126 /// msg: A string describing the situation where the wrong IpVersion was encountered.
127 ///
128 IpVersionError(msg: String) {
129 description("Ip version (ipv4 or ipv6) used when the other is expected"),
130 display("Ip version (ipv4 or ipv6) used when the other is expected, msg: {}", msg)
131 }
132
133 /// Attempted to use an unsupported (not Ipv4 or Ipv6) IP version.
134 ///
135 /// # Arguments
136 /// msg: A string describing the situation where an unsupported IP version is used.
137 ///
138 UnsupportedIpVersion(msg: String) {
139 description("Attempted to use an unsupported (not Ipv4 or Ipv6) IP version"),
140 display("Attempted to use an unsupported (not Ipv4 or Ipv6) IP version, msg: {}", msg)
141 }
142
143 /// Attempted to use a sender which has already been terminated.
144 ///
145 /// # Arguments
146 /// msg: A string describing why the error was returned.
147 ///
148 SenderAlreadyTerminated(msg: String) {
149 description("Attempted to use a sender which has already been terminated"),
150 display("Attempted to use a sender which has already been terminated, msg: {}", msg)
151 }
152
153 /// An error was encountered when attempting to merge DMX data together.
154 ///
155 /// # Arguments
156 /// msg: A string describing why the error was returned.
157 ///
158 DmxMergeError(msg: String) {
159 description("Error when merging DMX data"),
160 display("Error when merging DMX data, msg: {}", msg)
161 }
162
163 /// Packet was received out of sequence and so should be discarded.
164 ///
165 /// # Arguments
166 /// msg: A string describing why the error was returned.
167 ///
168 OutOfSequence(msg: String) {
169 description("Packet was received out of sequence and so should be discarded"),
170 display("Packet was received out of sequence and so should be discarded, msg: {}", msg)
171 }
172
173 /// A source terminated a universe and this was detected when trying to receive data.
174 /// This is only returned if the announce_stream_termination flag is set to true (default false).
175 ///
176 /// # Arguments
177 ///
178 /// src_cid: The CID of the source which sent the termination packet.
179 ///
180 /// uni: The universe that the termination packet is for.
181 ///
182 UniverseTerminated(src_cid: Uuid, uni: u16) {
183 description("A source terminated a universe and this was detected when trying to receive data"),
184 display("Source cid: {:?} terminated universe: {}", src_cid, uni)
185 }
186
187 /// A source universe timed out as no data was received on that universe within E131_NETWORK_DATA_LOSS_TIMEOUT as per ANSI E1.31-2018 Section 6.7.1.
188 ///
189 /// # Arguments
190 ///
191 /// src_cid: The CID of the source which timed out.
192 ///
193 /// uni: The universe that timed out.
194 ///
195 UniverseTimeout(src_cid: Uuid, uni: u16) {
196 description("A source universe timed out as no data was received within E131_NETWORK_DATA_LOSS_TIMEOUT as per ANSI E1.31-2018 Section 6.7.1"),
197 display("(Source,Universe) timed out: ({},{})", src_cid, uni)
198 }
199
200 /// When looking for a specific universe it wasn't found. This might happen for example if trying to mute a universe on a receiver that
201 /// wasn't being listened to.
202 ///
203 /// # Arguments
204 /// msg: A message describing why this error was returned.
205 ///
206 UniverseNotFound(msg: String) {
207 description("When looking for a specific universe it wasn't found"),
208 display("When looking for a specific universe it wasn't found, msg: {}", msg)
209 }
210
211 /// Attempted to find a source and failed. This might happen on a receiver for example if trying to remove a source which was never
212 /// registered or discovered.
213 ///
214 /// # Arguments
215 /// msg: A message describing why this error was returned / when the source was not found.
216 ///
217 SourceNotFound(msg: String) {
218 description("When looking for a specific source it wasn't found"),
219 display("Source not found, msg: {}", msg)
220 }
221
222 /// Thrown to indicate that the operation attempted is unsupported on the current OS
223 /// For example this is used to indicate that multicast-IPv6 isn't supported current on Windows.
224 ///
225 /// # Arguments
226 /// msg: A message describing why this error was returned / the operation that was not supported.
227 ///
228 OsOperationUnsupported(msg: String) {
229 description("Thrown to indicate that the operation attempted is unsupported on the current OS"),
230 display("Operation attempted is unsupported on the current OS, msg: {}", msg)
231 }
232
233 /// Thrown to indicate that the source has corrupted for the reason specified by the error chain.
234 /// This is currently only thrown if the source mutex is poisoned by a thread with access panic-ing.
235 /// This prevents the panic propagating to the user of this library and allows them to handle it appropriately
236 /// such as by creating a new source.
237 ///
238 /// # Arguments
239 /// msg: A message providing further details (if any) as to why the SourceCorrupt error was returned.
240 ///
241 SourceCorrupt(msg: String) {
242 description("The sACN source has corrupted due to an internal panic! and should no longer be used"),
243 display("The sACN source has corrupted due to an internal panic! and should no longer be used, {}", msg)
244 }
245 }
246 }
247}