mirror of https://git.48k.eu/ogclient
src: use explicit exception types in except Exception blocks
Capture only the relevant exception types in each except block. The capture of the Exception type means hiding information for unhandled error cases, even for syntax errors in the codebase. Using a more fine grained exception filtering improves error traceability.master
parent
dfde363aa6
commit
cbe7f8d49c
|
@ -52,7 +52,7 @@ class OgLiveOperations:
|
|||
try:
|
||||
proc = subprocess.call(["pkill", "-9", "browser"])
|
||||
proc = subprocess.Popen(["browser", "-qws", url])
|
||||
except Exception as e:
|
||||
except OSError as e:
|
||||
raise OgError('Cannot restart browser') from e
|
||||
|
||||
def _refresh_payload_disk(self, cxt, part_setup, num_disk):
|
||||
|
@ -144,7 +144,7 @@ class OgLiveOperations:
|
|||
try:
|
||||
r = shutil.copy(src, dst)
|
||||
tip_write_csum(image_name)
|
||||
except Exception as e:
|
||||
except (OSError, OgError) as e:
|
||||
raise OgError(f'Error copying image {image_name} to cache. Reported: {e}') from e
|
||||
|
||||
def _restore_image_unicast(self, repo, name, devpath, cache=False):
|
||||
|
@ -245,7 +245,7 @@ class OgLiveOperations:
|
|||
shell=True,
|
||||
executable=OG_SHELL)
|
||||
(output, error) = ogRest.proc.communicate()
|
||||
except Exception as e:
|
||||
except OSError as e:
|
||||
raise OgError(f'Error when running "shell run" subprocess: {e}') from e
|
||||
|
||||
if ogRest.proc.returncode != 0:
|
||||
|
|
|
@ -88,7 +88,7 @@ def _get_package_set_windows(hivepath):
|
|||
h = hivex.Hivex(hivepath)
|
||||
_fill_package_set_1(h, packages)
|
||||
_fill_package_set_2(h, packages)
|
||||
except Exception as e:
|
||||
except RuntimeError as e:
|
||||
logging.error(f'Hivex was not able to operate over {hivepath}. Reported: {e}')
|
||||
return packages
|
||||
|
||||
|
|
|
@ -139,12 +139,12 @@ def copy_windows_efi_bootloader(disk, partition):
|
|||
if os.path.exists(destination_dir):
|
||||
try:
|
||||
shutil.rmtree(destination_dir)
|
||||
except Exception as e:
|
||||
except OSError as e:
|
||||
raise OgError(f'Failed to delete {destination_dir}: {e}') from e
|
||||
logging.info(f'Copying {loader_dir} into {destination_dir}')
|
||||
try:
|
||||
shutil.copytree(loader_dir, destination_dir)
|
||||
except Exception as e:
|
||||
except OSError as e:
|
||||
raise OgError(f'Failed to copy {loader_dir} into {destination_dir}: {e}') from e
|
||||
finally:
|
||||
umount(mountpoint)
|
||||
|
|
Loading…
Reference in New Issue