Skip to main content

scdsu_core/
errors.rs

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