mirror of https://git.48k.eu/ogclient
src: change generic exception types to be more explicit
Replace exception types to be more explicit about the nature of the error. Improve the exception raising semantics by using the 'from' keyword, this wraps an older exception into a new one so it is still considered the same object.master
parent
167fd29634
commit
8741b2e272
|
@ -172,11 +172,11 @@ class OgLiveOperations:
|
|||
except:
|
||||
self._restartBrowser(self._url)
|
||||
if (not os.path.exists(image_path)):
|
||||
raise ValueError(f'Image file {image_path} does not exist')
|
||||
raise RuntimeError(f'Image file {image_path} does not exist')
|
||||
if (not tip_check_csum(repo, name)):
|
||||
raise ValueError(f'checksum file {name}.full.sum is missing in repository {repo}')
|
||||
raise RuntimeError(f'checksum file {name}.full.sum is missing in repository {repo}')
|
||||
|
||||
raise ValueError(f'Unexpected error when restoring image file {image_path}')
|
||||
raise RuntimeError(f'Unexpected error when restoring image file {image_path}')
|
||||
|
||||
self._restore_image(image_path, devpath)
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ def _boot_bios_windows(disk, part, mountpoint):
|
|||
with open(f'{mountpoint}/ogboot.secondboot', 'w') as f:
|
||||
f.write('\0' * (3072))
|
||||
except OSError as e:
|
||||
raise RuntimeError(f'Could not create ogboot files in Windows partition: {e}')
|
||||
raise OSError(f'Could not create ogboot files in Windows partition: {e}') from e
|
||||
|
||||
def _boot_uefi_windows(disk, part, mountpoint):
|
||||
logging.info(f'Booting windows system')
|
||||
|
|
|
@ -97,7 +97,7 @@ class OgQMP:
|
|||
self.sock.connect((self.ip, self.port))
|
||||
except socket.error as err:
|
||||
if err.errno == errno.ECONNREFUSED:
|
||||
raise Exception('cannot connect to qemu')
|
||||
raise RuntimeError('Cannot connect to QEMU')
|
||||
elif err.errno == errno.EINPROGRESS:
|
||||
pass
|
||||
|
||||
|
@ -114,11 +114,11 @@ class OgQMP:
|
|||
pass
|
||||
|
||||
if 'QMP' not in out:
|
||||
raise Exception('cannot handshake qemu')
|
||||
raise RuntimeError('Cannot handshake QEMU')
|
||||
|
||||
out = self.talk(str({"execute": "qmp_capabilities"}))
|
||||
if 'return' not in out:
|
||||
raise Exception('cannot handshake qemu')
|
||||
raise RuntimeError('Cannot handshake QEMU')
|
||||
|
||||
def disconnect(self):
|
||||
try:
|
||||
|
@ -142,10 +142,10 @@ class OgQMP:
|
|||
if self.sock in writable:
|
||||
try:
|
||||
self.sock.send(bytes(data, 'utf-8'))
|
||||
except:
|
||||
raise Exception('cannot talk to qemu')
|
||||
except Exception as e:
|
||||
raise RuntimeError('Cannot talk to QEMU') from e
|
||||
else:
|
||||
raise Exception('timeout when talking to qemu')
|
||||
raise RuntimeError('Timeout when talking to QEMU')
|
||||
|
||||
return self.recv(timeout=timeout)
|
||||
|
||||
|
@ -158,9 +158,9 @@ class OgQMP:
|
|||
out = self.sock.recv(4096).decode('utf-8')
|
||||
out = json.loads(out)
|
||||
except socket.error as err:
|
||||
raise Exception('cannot talk to qemu')
|
||||
raise RuntimeError('Cannot talk to QEMU') from err
|
||||
else:
|
||||
raise Exception('timeout when talking to qemu')
|
||||
raise RuntimeError('Timeout when talking to QEMU')
|
||||
return out
|
||||
|
||||
class OgVirtualOperations:
|
||||
|
|
|
@ -170,7 +170,7 @@ class QEMUMonitorProtocol(object):
|
|||
except socket.error as err:
|
||||
if err[0] == errno.EPIPE:
|
||||
return
|
||||
raise socket.error(err)
|
||||
raise socket.error(err) from err
|
||||
resp = self.__json_read()
|
||||
self.logger.debug("<<< %s", resp)
|
||||
return resp
|
||||
|
|
Loading…
Reference in New Issue