# Ruby\_exception - no implicit conversion of nil into string

**URL:** <https://discuss.elastic.co/t/ruby-exception-no-implicit-conversion-of-nil-into-string/179742>\
**Category:** Logstash\
**Created:** [May 6, 2019, 10:27am UTC](https://discuss.elastic.co/t/ruby-exception-no-implicit-conversion-of-nil-into-string/179742 "2019-05-06T10:27:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nane96](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@nane96](https://discuss.elastic.co/u/nane96)\
**Post date:** [May 6, 2019, 10:27am UTC](https://discuss.elastic.co/t/ruby-exception-no-implicit-conversion-of-nil-into-string/179742/1 "2019-05-06T10:27:58Z")

</div>

Hey,  
so I have this logstash conf-file with a part of ruby code in it that I mainly got though the help from one of you guys (managed to add one thing myself).

```
  ruby {
        code => '
                e = event.get("[@metadata][theXML][Event][EventData][Data]")
                if e.nil?
                        puts "empty"
                elsif e.kind_of?(Array)
                        e.each { |x|
                                event.set(x["Name"], x["content"])
                               }
                else
                        event.set(e["Name"], e["content"])
                end
                '
        }

```

I need it to work with this EventData part of an xml-File containing Log-Events, kinda looks like that (simplified):

```
<xmldata>
<Event>
...
<EventData>
   <Data Name="API">Plugin initialize</Data>
   <Data Name="Result">3221521586</Data>
</EventData>
</Event>
</xmldata>

```

And it works fine if the EventData part looks like this, also if it's completely empty or if there's only one Data-thing in there ( works fine here means I get an output looking like "API" =\> Plugin initialize; "Result" =\> ...).  
But I get a ruby\_exception (no implicit conversion of nil into String) as soon as it looks like this:

```
<EventData>
<Data>&lt;string&gt;LOG: Autovacuum-Launcher startet
&lt;/string&gt;
</Data> 
</EventData>

```

So when there are no subfields I guess, just one field called Data. I hoped I could just put another elsif-condition in there, but I don't know how to phrase the condition in this case.  
Unfortunately I don't know anything about ruby really, so really glad about any form of help here.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 3, 2019, 10:28am UTC](https://discuss.elastic.co/t/ruby-exception-no-implicit-conversion-of-nil-into-string/179742/2 "2019-06-03T10:28:03Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
