tof_dataclasses/
errors.rs

1//! Specific error types
2//!
3//!
4//!
5
6use std::error::Error;
7use std::fmt;
8
9////////////////////////////////////////
10
11#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
12#[repr(u8)]
13pub enum TofError {
14  CanNotConnect,
15}
16
17impl fmt::Display for TofError {
18  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19    let disp = serde_json::to_string(self).unwrap_or(
20      String::from("Error: cannot unwrap this SensorError"));
21    write!(f, "<TofError : {}>", disp)
22  }
23}
24
25impl Error for TofError {
26}
27
28////////////////////////////////////////
29
30#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
31#[repr(u8)]
32pub enum StagingError {
33  NoCurrentConfig,
34  QueEmpty,
35}
36
37impl fmt::Display for StagingError {
38  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
39    let disp = serde_json::to_string(self).unwrap_or(
40      String::from("Error: cannot unwrap this SensorError"));
41    write!(f, "<StagingError : {}>", disp)
42  }
43}
44
45impl Error for StagingError {
46}
47
48////////////////////////////////////////
49
50#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
51#[repr(u8)]
52pub enum PacketError {
53  WrongPacketType,
54  UnableToSendPacket,
55}
56
57impl fmt::Display for PacketError {
58  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59    let disp = serde_json::to_string(self).unwrap_or(
60      String::from("Error: cannot unwrap this SensorError"));
61    write!(f, "<PacketError : {}>", disp)
62  }
63}
64
65impl Error for PacketError {
66}
67
68////////////////////////////////////////
69
70#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
71#[repr(u8)]
72pub enum SensorError {
73  ReadoutError,
74}
75
76impl fmt::Display for SensorError {
77  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
78    let disp = serde_json::to_string(self).unwrap_or(
79      String::from("Error: cannot unwrap this SensorError"));
80    write!(f, "<ReadoutError : {}>", disp)
81  }
82}
83
84impl Error for SensorError {
85}
86
87////////////////////////////////////////
88
89#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
90#[repr(u8)]
91pub enum CalibrationError {
92  EmptyInputData,
93  CanNotConnectToMyOwnZMQSocket,
94  CalibrationFailed,
95  WrongBoardId,
96  IncompatibleFlightCalibrations,
97}
98
99impl fmt::Display for CalibrationError {
100  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
101    let disp = serde_json::to_string(self).unwrap_or(
102      String::from("Error: cannot unwrap this CalibrationError"));
103    write!(f, "<CalibrationError : {}>", disp)
104  }
105}
106
107impl Error for CalibrationError {
108}
109
110////////////////////////////////////////
111
112#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
113#[repr(u8)]
114pub enum RunError {
115  EmptyInputData,
116  CanNotConnectToMyOwnZMQSocket  
117}
118
119impl fmt::Display for RunError {
120  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
121    let disp = serde_json::to_string(self).unwrap_or(
122      String::from("Error: cannot unwrap this RunError"));
123    write!(f, "<RunError : {}>", disp)
124  }
125}
126
127impl Error for RunError {
128}
129
130////////////////////////////////////////
131
132#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
133#[repr(u8)]
134pub enum EventError {
135  EventIdMismatch
136}
137
138impl fmt::Display for EventError {
139  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
140    let disp = serde_json::to_string(self).unwrap_or(
141      String::from("Error: cannot unwrap this EventError"));
142    write!(f, "<EventError : {}>", disp)
143  }
144}
145
146impl Error for EventError {
147}
148
149////////////////////////////////////////
150
151/// Indicate issues with (de)serialization
152#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
153#[repr(u8)]
154pub enum SerializationError {
155  //HeaderNotFound,
156  TailInvalid,
157  HeadInvalid,
158  TrackerDelimiterInvalid,
159  TofDelimiterInvalid,
160  StreamTooShort,
161  StreamTooLong,
162  ValueNotFound,
163  EventFragment,
164  UnknownPayload,
165  IncorrectPacketType,
166  WrongByteSize,
167  JsonDecodingError,
168  TomlDecodingError,
169  Disconnected
170}
171
172impl fmt::Display for SerializationError {
173  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
174    let disp = serde_json::to_string(self).unwrap_or(
175      String::from("Error: cannot unwrap this SerializationError"));
176    write!(f, "<Serialization Error : {}>", disp)
177  }
178}
179
180impl Error for SerializationError {
181}
182
183////////////////////////////////////////
184
185#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
186#[repr(u8)]
187pub enum DecodingError {
188  //HeaderNotFound,
189  ChannelOutOfBounds,
190  UnknownType
191}
192
193impl fmt::Display for DecodingError {
194  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
195    let disp = serde_json::to_string(self).unwrap_or(
196      String::from("Error: cannot unwrap this DecodingError"));
197    write!(f, "<DecodingError Error : {}>", disp)
198  }
199}
200
201impl Error for DecodingError {
202}
203
204////////////////////////////////////////
205
206/// Error to be used for issues with 
207/// the communication to the MTB.
208#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
209#[repr(u8)]
210pub enum MasterTriggerError {
211  Unknown,
212  EventQueueEmpty,
213  MaskTooLarge,
214  BrokenPackage,
215  DAQNotAvailable,
216  PackageFormatIncorrect,
217  PackageHeaderIncorrect,
218  PackageFooterIncorrect,
219  FailedOperation,
220  UdpTimeOut,
221  DataTooShort
222}
223
224impl fmt::Display for MasterTriggerError {
225  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
226    let disp = serde_json::to_string(self).unwrap_or(
227      String::from("Error: cannot unwrap this MasterTriggerError"));
228    write!(f, "<MasterTriggerError : {}>", disp)
229  }
230}
231
232impl Error for MasterTriggerError {
233}
234
235// Implement the From trait to convert from Box<dyn StdError>
236impl From<Box<dyn std::error::Error>> for MasterTriggerError {
237  fn from(err: Box<dyn std::error::Error>) -> Self {
238    error!("Converting {err} to MasterTriggerError! Exact error type might be incorrect!");
239    MasterTriggerError::FailedOperation
240  }
241}
242
243////////////////////////////////////////
244
245
246/// Problems in waveform analysis
247#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
248#[repr(u8)]
249pub enum WaveformError {
250  TimeIndexOutOfBounds,
251  TimesTooSmall,
252  NegativeLowerBound,
253  OutOfRangeUpperBound,
254  OutOfRangeLowerBound,
255  DidNotCrossThreshold,
256  TooSpiky,
257}
258
259impl fmt::Display for WaveformError {
260  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
261    let disp = serde_json::to_string(self).unwrap_or(
262      String::from("Error: cannot unwrap this WaveformError"));
263    write!(f, "<WaveformError: {}>", disp)
264  }
265}
266
267// TODO is this needed?
268// DONE - Yes, we talked about it. I think you need 
269// it if you want to returnt Box<Error>
270impl Error for WaveformError {
271}
272
273////////////////////////////////////////
274
275
276/// IPBus provides a package format for
277/// sending UDP packets with a header.
278/// This is used by the MTB to send its
279/// packets over UDP
280#[derive(Debug, Copy, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
281#[repr(u8)]
282pub enum IPBusError {
283  DecodingFailed,
284  InvalidTransactionID,
285  InvalidPacketID,
286  NotAStatusPacket,
287  ConnectionTimeout,
288  UdpSendFailed,
289  UdpReceiveFailed
290}
291
292impl fmt::Display for IPBusError {
293  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
294    let disp = serde_json::to_string(self).unwrap_or(
295      String::from("Error: cannot unwrap this IPBusError"));
296    write!(f, "<IPBusError Error : {}>", disp)
297  }
298}
299
300impl Error for IPBusError {
301}
302
303////////////////////////////////////////
304
305#[derive(Debug,Copy,Clone, serde::Deserialize, serde::Serialize)]
306#[repr(u8)]
307pub enum AnalysisError {
308  MissingChannel,
309  NoChannel9,
310  InputBroken,
311  DataMangling
312}
313
314impl fmt::Display for AnalysisError {
315  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
316    let disp = serde_json::to_string(self).unwrap_or(
317      String::from("Error: cannot unwrap this AnalysisError"));
318    write!(f, "<AnalysisError : {}>", disp)
319  }
320}
321
322impl Error for AnalysisError {
323}
324
325////////////////////////////////////////
326
327#[derive(Debug,Copy,Clone, serde::Deserialize, serde::Serialize)]
328#[repr(u8)]
329pub enum UserError {
330  IneligibleChannelLabel,
331  NoChannel9Data,
332}
333
334impl fmt::Display for UserError {
335  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
336    let disp = serde_json::to_string(self).unwrap_or(
337      String::from("Error: cannot unwrap this UserError"));
338    write!(f, "<UserError : {}>", disp)
339  }
340}
341
342impl Error for UserError {
343}
344
345////////////////////////////////////////
346
347#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
348#[repr(u8)]
349pub enum SetError {
350  EmptyInputData,
351  CanNotConnectToMyOwnZMQSocket  
352}
353
354impl fmt::Display for SetError {
355  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
356    let disp = serde_json::to_string(self).unwrap_or(
357      String::from("Error: cannot unwrap this SetError"));
358    write!(f, "<SetError : {}>", disp)
359  }
360}
361
362impl Error for SetError {
363}
364
365////////////////////////////////////////
366
367#[derive(Debug, Copy, Clone, serde::Deserialize, serde::Serialize)]
368#[repr(u8)]
369pub enum CmdError {
370  UnknownError,
371  ListenError,
372  PingError,
373  MoniError,
374  SystemdRebootError,
375  PowerError,
376  CalibrationError,
377  ThresholdSetError,
378  PreampBiasSetError,
379  RunStopError,
380  RunStartError,
381  NotImplementedError
382}
383
384impl fmt::Display for CmdError {
385  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
386    let disp = serde_json::to_string(self).unwrap_or(
387      String::from("Error: cannot unwrap this CmdError"));
388    write!(f, "<CmdError : {}>", disp)
389  }
390}
391
392impl Error for CmdError {
393}