# How to troubleshoot "undefined method \`+' for nil:NilClass"

**URL:** https://discuss.elastic.co/t/how-to-troubleshoot-undefined-method-for-nil-nilclass/322121
**Category:** Logstash
**Tags:** docker
**Created:** [December 28, 2022, 7:50pm UTC](https://discuss.elastic.co/t/how-to-troubleshoot-undefined-method-for-nil-nilclass/322121 "2022-12-28T19:50:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![INS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ins/32/92827_2.png) [@INS](https://discuss.elastic.co/u/INS)
#### Post date: [December 28, 2022, 7:50pm UTC](https://discuss.elastic.co/t/how-to-troubleshoot-undefined-method-for-nil-nilclass/322121/1 "2022-12-28T19:50:25Z")

</div>

Hi  
Maybe You have some idea how to troubleshoot in the long pipeline the bug referring to

`[2022-12-28T19:47:41,016][ERROR][logstash.filters.ruby][main][1b91d552e5ff1ebff261eab8e51449b8aba605255321bb2b70376384a2493180] Ruby exception occurred: undefined method `+' for nil:NilClass {:class=\>"NoMethodError", :backtrace=\>["(ruby filter code):4:in `block in filter_method'", "/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-filter-ruby-3.1.8/lib/logstash/filters/ruby.rb:96:in `inline\_script'", "/usr/share/logstash/vendor/bundle/jruby/2.6.0/gems/logstash-filter-ruby-3.1.8/lib/logstash/filters/ruby.rb:89:in `filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:159:in `do\_filter'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:178:in `block in multi_filter'", "org/jruby/RubyArray.java:1865:in `each'", "/usr/share/logstash/logstash-core/lib/logstash/filters/base.rb:175:in `multi_filter'", "org/logstash/config/ir/compiler/AbstractFilterDelegatorExt.java:134:in `multi\_filter'", "/usr/share/logstash/logstash-core/lib/logstash/java\_pipeline.rb:300:in `block in start_workers'"]}`

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [December 28, 2022, 8:13pm UTC](https://discuss.elastic.co/t/how-to-troubleshoot-undefined-method-for-nil-nilclass/322121/2 "2022-12-28T20:13:39Z")

</div>

> [@INS](#):
>
> `undefined method `+' for nil:NilClass {:class=\>"NoMethodError", :backtrace=\>["(ruby filter code):4:in `block in filter_method'"`

You have a ruby filter with a code block.

```
    ruby {
        code => ' a = b + 1 '
    }

```

will report that exception with `:backtrace=>["(ruby filter code):2:in`, so you should be looking at the third line of your ruby code.

---

<div class="post-metadata">

### Author: ![INS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ins/32/92827_2.png) [@INS](https://discuss.elastic.co/u/INS)
#### Post date: [December 28, 2022, 8:33pm UTC](https://discuss.elastic.co/t/how-to-troubleshoot-undefined-method-for-nil-nilclass/322121/3 "2022-12-28T20:33:11Z")

</div>

```auto
	ruby {
		code => "
			event_millisecond = ('000' + event.get('millisecond').to_s).split(//).last(3).join
			event.set('event_timestamp', event.get('date') + ' ' + event.get('time') + '.' + event_millisecond)
		"
	}

```

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [December 28, 2022, 8:54pm UTC](https://discuss.elastic.co/t/how-to-troubleshoot-undefined-method-for-nil-nilclass/322121/4 "2022-12-28T20:54:47Z")

</div>

> [@INS](#):
>
> `event.set('event_timestamp', event.get('date') + ' ' + event.get('time') + '.' + event_millisecond)`

OK, so that is the third line of your code. It is processing an event that does not have [date] and/or [time] fields.

---

<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: [January 25, 2023, 8:55pm UTC](https://discuss.elastic.co/t/how-to-troubleshoot-undefined-method-for-nil-nilclass/322121/5 "2023-01-25T20:55:45Z")

</div>

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