Skip to main content

gondola_core/
errors.rs

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