coins_ledger/transports/native/
error.rs

1use thiserror::Error;
2
3// Mock the type in other target_os
4#[cfg(not(target_os = "linux"))]
5mod nix {
6    #[derive(thiserror::Error, Debug, Copy, Clone)]
7    pub enum Error {
8        #[error("")]
9        Unimplemented,
10    }
11}
12
13/// Ledger transport errors
14#[derive(Error, Debug)]
15pub enum NativeTransportError {
16    /// Device not found error
17    #[error("Ledger device not found")]
18    DeviceNotFound,
19    /// Device open error.
20    #[error("Error opening device. {0}. Hint: This usually means that the device is already in use by another transport instance.")]
21    CantOpen(hidapi_rusb::HidError),
22    /// SequenceMismatch
23    #[error("Sequence mismatch. Got {got} from device. Expected {expected}")]
24    SequenceMismatch {
25        /// The sequence returned by the device
26        got: u16,
27        /// The expected sequence
28        expected: u16,
29    },
30    /// Communication error
31    #[error("Ledger device: communication error `{0}`")]
32    Comm(&'static str),
33    /// Ioctl error
34    #[error(transparent)]
35    Ioctl(#[from] nix::Error),
36    /// i/o error
37    #[error(transparent)]
38    Io(#[from] std::io::Error),
39    /// HID error
40    #[error(transparent)]
41    Hid(#[from] hidapi_rusb::HidError),
42    /// UT8F error
43    #[error(transparent)]
44    UTF8(#[from] std::str::Utf8Error),
45    /// Termux USB FD env var does not exist or fails to parse. This error is
46    /// only returned by android-specific code paths, and may be safely ignored
47    /// by non-android users
48    #[error("Invalid TERMUX_USB_FD variable. Are you using termux-usb?")]
49    InvalidTermuxUsbFd,
50}