Commit 797506fc authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Simplify LUXI exceptions

Having only one exception hierarchy makes catching them simpler. Before
ProtocolError would derive directly from Exception, but with this patch
it'll also be in the hierarchy defined by the ganeti.errors module.
Separating encoding and decoding errors is not necessary at this point
as they're never handled separately, and merging them removes a few
lines from the code.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 24cd3744
......@@ -1302,8 +1302,6 @@ def FormatError(err):
obuf.write("Parameter Error: %s" % msg)
elif isinstance(err, errors.ParameterError):
obuf.write("Failure: unknown/wrong parameter name '%s'" % msg)
elif isinstance(err, errors.GenericError):
obuf.write("Unhandled Ganeti error: %s" % msg)
elif isinstance(err, luxi.NoMasterError):
obuf.write("Cannot communicate with the master daemon.\nIs it running"
" and listening for connections?")
......@@ -1313,6 +1311,8 @@ def FormatError(err):
elif isinstance(err, luxi.ProtocolError):
obuf.write("Unhandled protocol error while talking to the master daemon:\n"
"%s" % msg)
elif isinstance(err, errors.GenericError):
obuf.write("Unhandled Ganeti error: %s" % msg)
elif isinstance(err, JobSubmittedException):
obuf.write("JobID: %s\n" % err.args[0])
retcode = 0
......@@ -63,8 +63,8 @@ DEF_CTMO = 10
class ProtocolError(Exception):
"""Denotes an error in the server communication"""
class ProtocolError(errors.GenericError):
"""Denotes an error in the LUXI protocol"""
class ConnectionClosedError(ProtocolError):
......@@ -75,14 +75,6 @@ class TimeoutError(ProtocolError):
"""Operation timeout error"""
class EncodingError(ProtocolError):
"""Encoding failure on the sending side"""
class DecodingError(ProtocolError):
"""Decoding failure on the receiving side"""
class RequestError(ProtocolError):
"""Error on request
......@@ -185,7 +177,8 @@ class Transport:
if self.eom in msg:
raise EncodingError("Message terminator found in payload")
raise ProtocolError("Message terminator found in payload")
# TODO: sendall is not guaranteed to send everything
......@@ -320,7 +313,7 @@ class Client(object):
if (not isinstance(data, dict) or
KEY_SUCCESS not in data or
KEY_RESULT not in data):
raise DecodingError("Invalid response from server: %s" % str(data))
raise ProtocolError("Invalid response from server: %s" % str(data))
result = data[KEY_RESULT]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment