Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle MissingConverterException errors #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/logstash/inputs/jms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ def queue_event(msg, output_queue)

if @include_header
msg.attributes && msg.attributes.each do |field, value|
event.set(field.to_s, value) unless @skip_headers.include?(field.to_s)
set_field(event, field.to_s, value) unless @skip_headers.include?(field.to_s)
end
end

if @include_properties
msg.properties && msg.properties.each do |field, value|
event.set(field.to_s, value) unless @skip_properties.include?(field.to_s)
set_field(event, field.to_s, value) unless @skip_properties.include?(field.to_s)
end
end

Expand All @@ -300,6 +300,17 @@ def queue_event(msg, output_queue)
end
end

def set_field(event, field, value)
begin
event.set(field, value)
rescue Java::JavaLang::RuntimeException => e # Using RuntimeException as a common ancestor to MissingConverterException
# And IllegalArgumentException, which are used across different
# Logstash versions for Valuefier errors
logger.warn("Unable to convert value of type #{value.class} for field #{field}, falling back to using string representation",
:exception => e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:exception => e)
:exception => e.class, :message => e.message)

event.set(field, value.to_s)
end
end

def subscriber(session, params)
destination_key = @pub_sub ? :topic_name : :queue_name
Expand Down
13 changes: 13 additions & 0 deletions spec/inputs/unit/jms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@
end
end

describe '#set_field' do
let(:event) { LogStash::Event.new }
it 'should set the field correctly' do
plugin.set_field(event, "hello", "fff")
expect(event.get("hello")).to eql("fff")
end

it 'should set handle field values that are not convertible' do
plugin.set_field(event, "hello", Date.new(1999,1,1))
expect(event.get("hello")).to eql("1999-01-01")
end
end

describe '#error_hash' do
context 'should handle Java exceptions with a chain of causes' do
let (:raised) { java.lang.Exception.new("Outer", java.lang.RuntimeException.new("middle", java.io.IOException.new("Inner")))}
Expand Down