From 1938003d48515fe47efd3c7ba44dc6423371e71c Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Mon, 24 Sep 2007 17:55:15 -0300 Subject: [PATCH] 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. --- pymindaemon.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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: -- 2.43.0