From c54dd0d43b83cb5c4a916c76f6d533d7ff25cfcf Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Fri, 17 Jan 2014 16:31:30 -0500 Subject: [PATCH] catch encoding error in plugin --- zmq_notify.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/zmq_notify.rb b/zmq_notify.rb index 68f2b20..2c383f3 100644 --- a/zmq_notify.rb +++ b/zmq_notify.rb @@ -21,7 +21,7 @@ # zmq = ctx.socket( ZMQ::SUB ) # zmq.connect( "tcp://example.com:2428" ) # zmq.setsockopt( ZMQ::SUBSCRIBE, '' ) -# +# # loop do # pp YAML.load( zmq.recv ) # end @@ -241,7 +241,13 @@ class ZMQNotify # ignored = self.ignore_tags.split( ',' ) tags = tags.split( ',' ) - return WEECHAT_RC_OK unless ( ignored & tags ).empty? + return WEECHAT_RC_OK unless ( ignored & tags ).empty? + + message = if message.respond_to?(:encode) + message.encode('UTF-8', invalid: :replace, undef: :replace) + else + message + end notify = { :highlight => ! highlight.to_i.zero?, @@ -258,7 +264,11 @@ class ZMQNotify # self.print_info "Message notification: %p" % [ notify ] if DEBUG if self.use_json.true? - self.zmq.send( notify.to_json ) + begin + self.zmq.send( notify.to_json ) + rescue Encoding::UndefinedConversionError => ex + self.print_info "Failed encoding msg to JSON [#{notify.inspect}]" + end else self.zmq.send( notify.to_yaml ) end