mirror of https://git.48k.eu/ogclient
live: improve exception handling in image_create
Reduce the scope of the try except block that controls the case of deleting the image backup in case of error. Now it only covers the section of code after backup creation and up to image verification. Check when the Exception is an OgError to raise with added context. Prevent the deletion of the target image in case of error before the backup creation. Bundle the backup creation on its own try except block to give more feedback on a failed backup creation. Enables a better error management allowing unhandled exceptions to be reported properly.master
parent
cbe7f8d49c
commit
e19437290d
|
@ -421,7 +421,6 @@ class OgLiveOperations:
|
|||
if ogRest.terminated:
|
||||
return
|
||||
|
||||
try:
|
||||
diskname = get_disks()[disk-1]
|
||||
cxt = fdisk.Context(f'/dev/{diskname}', details=True)
|
||||
pa = None
|
||||
|
@ -457,9 +456,13 @@ class OgLiveOperations:
|
|||
|
||||
logfile = open('/tmp/command.log', 'wb', 0)
|
||||
|
||||
try:
|
||||
if os.path.exists(image_path) and backup:
|
||||
shutil.move(image_path, f'{image_path}.ant')
|
||||
except OSError as e:
|
||||
raise OgError(f'Cannot create backup for {image_path}: {e}') from e
|
||||
|
||||
try:
|
||||
p1 = Popen(cmd1, stdout=PIPE, stderr=logfile)
|
||||
p2 = Popen(cmd2, stdin=p1.stdout)
|
||||
p1.stdout.close()
|
||||
|
@ -493,7 +496,11 @@ class OgLiveOperations:
|
|||
shutil.move(f'{image_path}.ant', image_path)
|
||||
|
||||
self._restartBrowser(self._url)
|
||||
|
||||
if isinstance(e, OgError):
|
||||
raise OgError(f'Failed to create image for {fstype} filesystem in device {padev}: {e}') from e
|
||||
else:
|
||||
raise
|
||||
|
||||
try:
|
||||
st = os.stat(image_path)
|
||||
|
|
Loading…
Reference in New Issue