From: Leandro Lucarella Date: Mon, 24 Sep 2007 20:55:15 +0000 (-0300) Subject: Add a simple error reporting to the protocol. X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/1938003d48515fe47efd3c7ba44dc6423371e71c?ds=sidebyside;hp=--cc Add a simple error reporting to the protocol. A new response type is added "ERROR", which indicates a failure in the command execution. In the future different types of error could be defined. --- 1938003d48515fe47efd3c7ba44dc6423371e71c diff --git a/pymindaemon.py b/pymindaemon.py index 1ddef6c..79780e2 100644 --- a/pymindaemon.py +++ b/pymindaemon.py @@ -58,12 +58,17 @@ class PyminDaemon(EventLoop): def handle(self): r"handle() -> None :: Handle incoming events using the dispatcher." (msg, addr) = self.file.recvfrom(65535) - result = self.dispatcher.dispatch(msg) + try: + result = self.dispatcher.dispatch(msg) + response = 'OK ' + except Exception, e: + result = str(e) + response = 'ERROR ' if result is None: - msg = 'OK 0' + response += '0' else: - msg = 'OK %d\n%s' % (len(str(result)), result) - self.file.sendto(msg, addr) + response += '%d\n%s' % (len(str(result)), result) + self.file.sendto(response, addr) #try: # d.dispatch(msg) #except dis.BadRouteError, inst: