briefcase icon indicating copy to clipboard operation
briefcase copied to clipboard

Briefcase crashes if `adb devices` returns incomplete information

Open mhsmith opened this issue 3 years ago • 1 comments

Describe the bug

I somehow ended up in a situation where adb devices returned the following:

List of devices attached
emulator-5554          device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64 device:emulator64_x86_64_arm64 transport_id:1
emulator-5556          device transport_id:2

Despite emulator-5556 having incomplete information, it still worked perfectly well with other adb commands. However, Briefcase crashed with a KeyError because it expects the "model" field to always be there. I was able to work around this with the following change, which I don't have time right now to make into a fully-unit-tested PR:

diff --git a/src/briefcase/integrations/android_sdk.py b/src/briefcase/integrations/android_sdk.py
index 12c7b20..a3752b1 100644
--- a/src/briefcase/integrations/android_sdk.py
+++ b/src/briefcase/integrations/android_sdk.py
@@ -656,7 +658,10 @@ connection.
                         details[key] = value

                     if parts[1] == "device":
-                        name = details["model"].replace("_", " ")
+                        try:
+                            name = details["model"].replace("_", " ")
+                        except KeyError:
+                            name = "Unknown device (no model name)"
                         authorized = True
                     elif parts[1] == "offline":
                         name = "Unknown device (offline)"

Environment:

  • Operating System: Windows 10
  • Python version: 3.8
  • Software versions:
    • Briefcase: f000a5f3

mhsmith avatar Aug 10 '22 18:08 mhsmith

Weird... but the proposed fix seems reasonable.

freakboy3742 avatar Aug 11 '22 04:08 freakboy3742

@freakboy3742 I can do this. I have a question should authorized be set to false if there is no model?

PrestonMclean avatar Sep 26 '22 17:09 PrestonMclean

@PrestonMclean Based on @mhsmith's report, I think we can say the device should be authorized - his report indicates that a "no model" device was able to run.

freakboy3742 avatar Sep 27 '22 00:09 freakboy3742

Fixed by #876

freakboy3742 avatar Sep 28 '22 02:09 freakboy3742