--- a/bin/pvl.irker-syslog Sun Jan 20 15:39:44 2013 +0200
+++ b/bin/pvl.irker-syslog Sun Jan 20 15:40:37 2013 +0200
@@ -145,6 +145,13 @@
# 0 is controlled exit
return 0
+ except pvl.irk.IrkError as ex :
+ log.error("irker: %s", ex)
+
+ # XXX: copy-pasta
+ close_syslog(syslog)
+ return 0
+
# quit unless we have something to poll
if not syslog.poll :
break
--- 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?
"""