From adceed22ad3d8b6aa1e6d1aee56ae0c9a0a751aa Mon Sep 17 00:00:00 2001 From: Daemon Coder <11915375+codefiles@users.noreply.github.com> Date: Thu, 4 May 2023 03:45:43 -0400 Subject: Fix logic errors in `_fetch_lsblk_info()` (#1754) --- archinstall/lib/disk/device_model.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'archinstall') diff --git a/archinstall/lib/disk/device_model.py b/archinstall/lib/disk/device_model.py index 987a1e8a..8e26b1d7 100644 --- a/archinstall/lib/disk/device_model.py +++ b/archinstall/lib/disk/device_model.py @@ -974,32 +974,33 @@ def _fetch_lsblk_info(dev_path: Optional[Union[Path, str]] = None, retry: int = if retry == 0: retry = 1 - result = None - - for i in range(retry): + for retry_attempt in range(retry): try: result = SysCommand(f'lsblk --json -b -o+{lsblk_fields} {dev_path}') + break except SysCallError as error: # Get the output minus the message/info from lsblk if it returns a non-zero exit code. if error.worker: err = error.worker.decode('UTF-8') log(f'Error calling lsblk: {err}', level=logging.DEBUG) - time.sleep(1) else: raise error - if result and result.exit_code == 0: - try: - if decoded := result.decode('utf-8'): - block_devices = json.loads(decoded) - blockdevices = block_devices['blockdevices'] - return [LsblkInfo.from_json(device) for device in blockdevices] - except json.decoder.JSONDecodeError as err: - log(f"Could not decode lsblk JSON: {result}", fg="red", level=logging.ERROR) - raise err + if retry_attempt == retry - 1: + raise error - raise DiskError(f'Failed to read disk "{dev_path}" with lsblk') + time.sleep(1) + + try: + if decoded := result.decode('utf-8'): + block_devices = json.loads(decoded) + blockdevices = block_devices['blockdevices'] + return [LsblkInfo.from_json(device) for device in blockdevices] + except json.decoder.JSONDecodeError as err: + log(f"Could not decode lsblk JSON: {result}", fg="red", level=logging.ERROR) + raise err + raise DiskError(f'Failed to read disk "{dev_path}" with lsblk') def get_lsblk_info(dev_path: Union[Path, str]) -> LsblkInfo: if infos := _fetch_lsblk_info(dev_path): -- cgit v1.2.3-70-g09d2