Skip to main content

scdsu_core/
errors.rs

1use thiserror::Error;
2
3/// Errors that can occur when running the UDP server.
4#[derive(Error, Debug)]
5pub enum ServerError {
6    /// The HID Api failed to initialize when starting the server.
7    #[error("could not initialize HID API: {0}")]
8    HidApi(#[from] hidapi::HidError),
9    /// The `UdpSocket` could not be cloned.
10    #[error("failed to clone UdpSocket: {0}")]
11    UdpSocketCloneFailed(std::io::Error),
12    /// There was an error performing a `UdpSocket` operation.
13    #[error("UdpSocket operation error: {0}")]
14    UdpSocketOperationError(std::io::Error),
15}
16
17/// Errors that can occur when opening, initializing, or reading from devices.
18#[derive(Error, Debug)]
19pub enum DeviceError {
20    /// The Device failed to open
21    #[error("Failed to open Device")]
22    NoDeviceFound,
23    /// A device operation resulted in a [`std::io::Error`]
24    #[error("IO Error: {0}")]
25    IO(#[from] std::io::Error),
26    /// A device operation resulted in a [`hidapi::HidError`]
27    #[error("HID Error: {0}")]
28    Hid(#[from] hidapi::HidError),
29    /// A device report was not the required length
30    #[error("Short read: got {0} bytes, expected at least {1}")]
31    ShortRead(usize, usize),
32    /// A device report was invalid
33    #[error("Invalid report (first byte: 0x{0:02x})")]
34    InvalidReport(u8),
35}