mirror of
https://github.com/vbatts/flaming-happiness.git
synced 2024-11-23 09:05:40 +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
|
@ -243,6 +243,12 @@ class ZMQNotify
|
|||
tags = tags.split( ',' )
|
||||
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?,
|
||||
:type => data[ :type ],
|
||||
|
@ -258,7 +264,11 @@ class ZMQNotify
|
|||
#
|
||||
self.print_info "Message notification: %p" % [ notify ] if DEBUG
|
||||
if self.use_json.true?
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue