scripts: sd_fusing: handle lsblk errors better
authorMateusz Majewski <m.majewski2@samsung.com>
Fri, 7 Jun 2024 10:44:44 +0000 (12:44 +0200)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Wed, 4 Dec 2024 11:00:01 +0000 (12:00 +0100)
This makes the error handling a bit more consistent with the rest of the
script by logging an error and doing a sys.exit(1).

Returning an error by returning None would mean that it would need to be
handled elsewhere. However this does not happen, resulting in a
confusing runtime error

    TypeError: can only concatenate str (not "NoneType") to str

as well as warnings in some editors.

Change-Id: I6b3f382e93846c3165d1a8221e2faf7dbf295a86

sd_fusing.py

index ef0e754896102760b3dfacee39a58cc1291ff70d..2513bdc078a11d251ca2b930df19f987fd86385c 100755 (executable)
@@ -975,24 +975,29 @@ def get_partition_device(device, idx):
                           stdout=subprocess.PIPE)
     if proc.returncode != 0:
         logging.error("lsblk has failed")
-        return None
+        sys.exit(1)
     part_re = re.compile(f"^part\s+(.*[^0-9]{idx})$")
     for l in proc.stdout.decode('utf-8').splitlines():
         match = part_re.match(l)
         if match:
             return match[1]
-    return None
+    logging.error("device entry not found")
+    sys.exit(1)
 
 def get_device_kname(device):
     argv = ['lsblk', device, '-o', 'TYPE,KNAME']
     logging.debug(" ".join(argv))
     proc = subprocess.run(argv,
                           stdout=subprocess.PIPE)
+    if proc.returncode != 0:
+        logging.error("lsblk has failed")
+        sys.exit(1)
     for l in proc.stdout.decode('utf-8').splitlines():
         match = re.search(f"^(disk|loop)\s+(.*)", l)
         if match:
             return match[2]
-    return None
+    logging.error("kname entry not found")
+    sys.exit(1)
 
 def do_fuse_file(f, name, target):
     indexes = target.get_partition_index_list(name)