]> git.llucax.com Git - software/pymin.git/commitdiff
Add a simple error reporting to the protocol.
authorLeandro Lucarella <llucarella@integratech.com.ar>
Mon, 24 Sep 2007 20:55:15 +0000 (17:55 -0300)
committerLeandro Lucarella <llucarella@integratech.com.ar>
Mon, 24 Sep 2007 20:55:15 +0000 (17:55 -0300)
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

index 1ddef6c5d2bff19927580e11ceeb368368346a3d..79780e22162d075ba71ecae0ed195383279d562f 100644 (file)
@@ -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)
     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:
         if result is None:
-            msg = 'OK 0'
+            response += '0'
         else:
         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:
         #try:
         #    d.dispatch(msg)
         #except dis.BadRouteError, inst: