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 <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 24cd3744
...@@ -1302,8 +1302,6 @@ def FormatError(err): ...@@ -1302,8 +1302,6 @@ def FormatError(err):
obuf.write("Parameter Error: %s" % msg) obuf.write("Parameter Error: %s" % msg)
elif isinstance(err, errors.ParameterError): elif isinstance(err, errors.ParameterError):
obuf.write("Failure: unknown/wrong parameter name '%s'" % msg) 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): elif isinstance(err, luxi.NoMasterError):
obuf.write("Cannot communicate with the master daemon.\nIs it running" obuf.write("Cannot communicate with the master daemon.\nIs it running"
" and listening for connections?") " and listening for connections?")
...@@ -1313,6 +1311,8 @@ def FormatError(err): ...@@ -1313,6 +1311,8 @@ def FormatError(err):
elif isinstance(err, luxi.ProtocolError): elif isinstance(err, luxi.ProtocolError):
obuf.write("Unhandled protocol error while talking to the master daemon:\n" obuf.write("Unhandled protocol error while talking to the master daemon:\n"
"%s" % msg) "%s" % msg)
elif isinstance(err, errors.GenericError):
obuf.write("Unhandled Ganeti error: %s" % msg)
elif isinstance(err, JobSubmittedException): elif isinstance(err, JobSubmittedException):
obuf.write("JobID: %s\n" % err.args[0]) obuf.write("JobID: %s\n" % err.args[0])
retcode = 0 retcode = 0
......
...@@ -63,8 +63,8 @@ DEF_CTMO = 10 ...@@ -63,8 +63,8 @@ DEF_CTMO = 10
DEF_RWTO = 60 DEF_RWTO = 60
class ProtocolError(Exception): class ProtocolError(errors.GenericError):
"""Denotes an error in the server communication""" """Denotes an error in the LUXI protocol"""
class ConnectionClosedError(ProtocolError): class ConnectionClosedError(ProtocolError):
...@@ -75,14 +75,6 @@ class TimeoutError(ProtocolError): ...@@ -75,14 +75,6 @@ class TimeoutError(ProtocolError):
"""Operation timeout error""" """Operation timeout error"""
class EncodingError(ProtocolError):
"""Encoding failure on the sending side"""
class DecodingError(ProtocolError):
"""Decoding failure on the receiving side"""
class RequestError(ProtocolError): class RequestError(ProtocolError):
"""Error on request """Error on request
...@@ -185,7 +177,8 @@ class Transport: ...@@ -185,7 +177,8 @@ class Transport:
""" """
if self.eom in msg: if self.eom in msg:
raise EncodingError("Message terminator found in payload") raise ProtocolError("Message terminator found in payload")
self._CheckSocket() self._CheckSocket()
try: try:
# TODO: sendall is not guaranteed to send everything # TODO: sendall is not guaranteed to send everything
...@@ -320,7 +313,7 @@ class Client(object): ...@@ -320,7 +313,7 @@ class Client(object):
if (not isinstance(data, dict) or if (not isinstance(data, dict) or
KEY_SUCCESS not in data or KEY_SUCCESS not in data or
KEY_RESULT not in data): 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] 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