ledger_bluetooth/
errors.rs

1use std::sync::{MutexGuard, PoisonError};
2
3use btleplug::platform;
4/*******************************************************************************
5*
6*  Licensed under the Apache License, Version 2.0 (the "License");
7*  you may not use this file except in compliance with the License.
8*  You may obtain a copy of the License at
9*
10*      http://www.apache.org/licenses/LICENSE-2.0
11*
12*  Unless required by applicable law or agreed to in writing, software
13*  distributed under the License is distributed on an "AS IS" BASIS,
14*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15*  See the License for the specific language governing permissions and
16*  limitations under the License.
17********************************************************************************/
18use thiserror::Error;
19
20#[derive(Error, Debug)]
21pub enum LedgerBleError {
22    /// Device not found error
23    #[error("Ledger device not found")]
24    DeviceNotFound,
25    /// Communication error
26    #[error("Ledger device: communication error `{0}`")]
27    Comm(&'static str),
28    /// Communication error
29    #[error("Ledger device: received an invalid packet")]
30    InvalidPacket,
31    /// i/o error
32    #[error("Ledger device: i/o error")]
33    Io(#[from] std::io::Error),
34    /// UT8F error
35    #[error("Ledger device: UTF8 error")]
36    UTF8(#[from] std::str::Utf8Error),
37    /// UT8F error
38    #[error("Ledger device: BLE error")]
39    Ble(#[from] btleplug::Error),
40    /// Poison error
41    #[error("Ledger device: BLE error")]
42    Poison(#[from] PoisonError<MutexGuard<'static, platform::Peripheral>>),
43}