pvl/irk.py
changeset 145 a72b6aca2619
parent 134 99a8987fc424
--- a/pvl/irk.py	Sun Jan 20 15:39:44 2013 +0200
+++ b/pvl/irk.py	Sun Jan 20 15:40:37 2013 +0200
@@ -37,6 +37,11 @@
     # None -> stdout
     return Irker(options.irker, options) # options.irker_*
 
+class IrkError (Exception) :
+    """
+        Irk write error.
+    """
+
 class Irk (object) :
     """
         Irker JSON connection speaks JSON over a stream.
@@ -88,13 +93,22 @@
 
     def __call__ (self, **opts) :
         """
-            Raises IOError on write errors.
+            Send given json.
+
+            Raises IrkError on write EOF.
+
+            XXX: Raises socket.error/IOError on write errors?
         """
 
         log.debug("%s", opts)
         
-        # write line + flush
-        self.send(json.dumps(opts))
+        try :
+            # write line + flush
+            self.send(json.dumps(opts))
+
+        except EOFError as ex :
+            # XXX: also socket.error etc?
+            raise IrkError("%s: send eof: %s" % (self, ex))
         
         # XXX: self.send.flush()
 
@@ -114,6 +128,8 @@
 class IrkerTarget (object) :
     """
         A channel on an Irk connection.
+            
+        Raises IrkError if irk(..) fails.
     """
 
     def __init__ (self, irker, target, notice=None, part=None) :
@@ -187,6 +203,8 @@
         """
             Send on current irker connection.
 
+            Raises IrkError if irk(..) fails.
+
             TODO: handle errors and reconnect?
             """