Blob Blame History Raw
From c6eb801a233d3623668ccca73a0f853671651a8b Mon Sep 17 00:00:00 2001
From: samtygier <samtygier@yahoo.co.uk>
Date: Tue, 10 Dec 2019 10:11:45 +0000
Subject: [PATCH] Handle error from rfkill (#94)

Fixes #88

In the case where `/dev/rfkill` does not exist `rfkill` will return
false which triggers a backtrace in blueberry, which may then
trigger a distro's bug reporting tool. This is common on virtual
machines.

Instead handle the error. `res` gets set to an empty string, which
the rest of the funtion interprets and having no adapter. This allows
blueberry to launch with a window saying

"No Bluetooth adapters found"
---
 usr/lib/blueberry/rfkillMagic.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/usr/lib/blueberry/rfkillMagic.py b/usr/lib/blueberry/rfkillMagic.py
index 3d05f6f..705ce95 100644
--- a/usr/lib/blueberry/rfkillMagic.py
+++ b/usr/lib/blueberry/rfkillMagic.py
@@ -30,7 +30,13 @@ def __init__(self, output_callback, debug):
         self.start_event_monitor()
 
     def adapter_check(self):
-        res = subprocess.check_output(RFKILL_CHK).decode('utf-8')
+        proc = subprocess.run(RFKILL_CHK, stdout=subprocess.PIPE)
+        if proc.returncode != 0:
+            self.debug("Error running command: %s." % RFKILL_CHK)
+            res = ""
+        else:
+            res = proc.stdout.decode('utf-8')
+
         match = None
         have_adapter = False