From 800e07aa9618fc90bfd0b589d596cf2b0fcc469f Mon Sep 17 00:00:00 2001 From: Alan Moore Date: Mon, 2 Oct 2017 19:55:42 -0500 Subject: [PATCH] Fix crash when fdisk fails on usb disk device In the event that `fdisk -l` fails on a partition or device (e.g., a usb card reader has no media), don't crash the program. Just return None, since this is just a partition that the program can't use. Fixes #180. --- scripts/usb.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/usb.py b/scripts/usb.py index 36969e9..dbd90b1 100644 --- a/scripts/usb.py +++ b/scripts/usb.py @@ -219,7 +219,11 @@ def details_udev(usb_disk_part): gen.log("ERROR: Unknown disk/partition (%s)" % str(usb_disk_part)) return None - fdisk_cmd_out = subprocess.check_output('fdisk -l ' + usb_disk_part, shell=True) + try: + fdisk_cmd_out = subprocess.check_output('fdisk -l ' + usb_disk_part, shell=True) + except subprocess.CalledProcessError: + gen.log("ERROR: fdisk failed on disk/partition (%s)" % str(usb_disk_part)) + return None if b'Extended' in fdisk_cmd_out: mount_point = ''