mirror of
https://github.com/vbatts/flaming-happiness.git
synced 2025-05-17 02:40:07 +00:00
catch encoding error in plugin
This commit is contained in:
parent
87d3ae96d7
commit
c54dd0d43b
1 changed files with 13 additions and 3 deletions
|
@ -21,7 +21,7 @@
|
||||||
# zmq = ctx.socket( ZMQ::SUB )
|
# zmq = ctx.socket( ZMQ::SUB )
|
||||||
# zmq.connect( "tcp://example.com:2428" )
|
# zmq.connect( "tcp://example.com:2428" )
|
||||||
# zmq.setsockopt( ZMQ::SUBSCRIBE, '' )
|
# zmq.setsockopt( ZMQ::SUBSCRIBE, '' )
|
||||||
#
|
#
|
||||||
# loop do
|
# loop do
|
||||||
# pp YAML.load( zmq.recv )
|
# pp YAML.load( zmq.recv )
|
||||||
# end
|
# end
|
||||||
|
@ -241,7 +241,13 @@ class ZMQNotify
|
||||||
#
|
#
|
||||||
ignored = self.ignore_tags.split( ',' )
|
ignored = self.ignore_tags.split( ',' )
|
||||||
tags = 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 = {
|
notify = {
|
||||||
:highlight => ! highlight.to_i.zero?,
|
:highlight => ! highlight.to_i.zero?,
|
||||||
|
@ -258,7 +264,11 @@ class ZMQNotify
|
||||||
#
|
#
|
||||||
self.print_info "Message notification: %p" % [ notify ] if DEBUG
|
self.print_info "Message notification: %p" % [ notify ] if DEBUG
|
||||||
if self.use_json.true?
|
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
|
else
|
||||||
self.zmq.send( notify.to_yaml )
|
self.zmq.send( notify.to_yaml )
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue