summaryrefslogtreecommitdiffstats
path: root/src/virtual/ogOperations.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-03-18 20:26:31 +0100
committerlupoDharkael <izhe@hotmail.es>2024-03-21 10:29:57 +0100
commit8741b2e2724fabb25465c06c3a4f881d9aa28d67 (patch)
tree05d065a70a6d0b28c714047f6c111077827cc1c1 /src/virtual/ogOperations.py
parent167fd296343870a5e6f94eaba749bc7722d2e7cb (diff)
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.
Diffstat (limited to 'src/virtual/ogOperations.py')
-rw-r--r--src/virtual/ogOperations.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py
index 930382d..0819a76 100644
--- a/src/virtual/ogOperations.py
+++ b/src/virtual/ogOperations.py
@@ -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: