Now all errors that should be reported back to the pymin client should
inherit from dispatcher.HandlerError. Any other error is reported to the
client as an internal server error and it's printed in the daemon standard
output for debugging purposes. A new line is now appended to errors
reported to the client for better consistency with OK responses.
command - is the command that raised the exception, expressed as a list of
paths (or subcommands).
"""
command - is the command that raised the exception, expressed as a list of
paths (or subcommands).
"""
- def __init__(self, command):
- r"""Initialize the Error object.
+class HandlerError(Error):
+ r"""
+ HandlerError(command) -> HandlerError instance :: Base handlers exception.
- See Error class documentation for more info.
- """
- self.command = command
+ All exceptions raised by the handlers should inherit from this one, so
+ dispatching errors could be separated from real programming errors (bugs).
+ """
+ pass
- def __str__(self):
- return 'Command not found: "%s"' % ' '.join(self.command)
class CommandNotFoundError(Error):
r"""
class CommandNotFoundError(Error):
r"""
This exception is raised when the command received can't be dispatched
because there is no handlers to process it.
"""
This exception is raised when the command received can't be dispatched
because there is no handlers to process it.
"""
+
+ def __init__(self, command):
+ r"""Initialize the Error object.
+
+ See Error class documentation for more info.
+ """
+ self.command = command
+
+ def __str__(self):
+ return 'Command not found: "%s"' % ' '.join(self.command)
def handler(f):
f._dispatcher_handler = True
def handler(f):
f._dispatcher_handler = True
if result is not None:
result = serializer.serialize(result)
response = u'OK '
if result is not None:
result = serializer.serialize(result)
response = u'OK '
+ except dispatcher.Error, e:
+ result = unicode(e) + u'\n'
+ response = u'ERROR '
+ import traceback
+ result = u'Internal server error'
+ traceback.print_exc() # TODO logging!
response = u'ERROR '
if result is None:
response += u'0'
response = u'ERROR '
if result is None:
response += u'0'
except ImportError:
import pickle
except ImportError:
import pickle
- from dispatcher import handler
+ from seqtools import Sequence
- def handler(f): return f # NOP for testing
+ # NOP for testing
+ class Sequence: pass
+try:
+ from dispatcher import handler, HandlerError
+except ImportError:
+ # NOP for testing
+ class HandlerError(RuntimeError): pass
+ def handler(f): return f
__ALL__ = ('DhcpHandler',)
__ALL__ = ('DhcpHandler',)
template_dir = path.join(path.dirname(__file__), 'templates')
template_dir = path.join(path.dirname(__file__), 'templates')
-class Error(RuntimeError):
+class Error(HandlerError):
r"""
Error(command) -> Error instance :: Base DhcpHandler exception class.
r"""
Error(command) -> Error instance :: Base DhcpHandler exception class.
self.message = 'Parameter not found: "%s"' % paramname
self.message = 'Parameter not found: "%s"' % paramname
-class Host(seqtools.Sequence):
r"""Host(name, ip, mac) -> Host instance :: Class representing a host.
name - Host name, should be a fully qualified name, but no checks are done.
r"""Host(name, ip, mac) -> Host instance :: Class representing a host.
name - Host name, should be a fully qualified name, but no checks are done.