Skip to content

Commit e8a1ed3

Browse files
hlxidmgjm
authored andcommitted
Improve error handling in BLE device enumeration
1 parent c273d4c commit e8a1ed3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/ble.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ impl Device {
3636
/// This function panics if it is unable to access the Bluetooth adapter.
3737
pub async fn enumerate_duration(scan_duration: Duration) -> Result<Vec<Self>> {
3838
// Run device scan
39-
let manager = Manager::new().await.unwrap();
40-
let adapter = manager.adapters().await.unwrap().pop().unwrap();
39+
let manager = Manager::new().await?;
40+
let adapter = manager.adapters().await?.pop();
41+
if adapter.is_none() {
42+
return Err(anyhow::anyhow!("No Bluetooth adapter found"));
43+
}
44+
45+
let adapter = adapter.unwrap();
4146
adapter.start_scan(ScanFilter::default()).await?;
4247
task::sleep(scan_duration).await;
4348

0 commit comments

Comments
 (0)