# Logstash new codec plugin fails while using

**URL:** <https://discuss.elastic.co/t/logstash-new-codec-plugin-fails-while-using/221756>\
**Category:** Logstash\
**Created:** [March 2, 2020, 6:49pm UTC](https://discuss.elastic.co/t/logstash-new-codec-plugin-fails-while-using/221756 "2020-03-02T18:49:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![i-mohit-a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/i-mohit-a/32/52975_2.png) [@i-mohit-a](https://discuss.elastic.co/u/i-mohit-a)\
**Post date:** [March 2, 2020, 6:49pm UTC](https://discuss.elastic.co/t/logstash-new-codec-plugin-fails-while-using/221756/1 "2020-03-02T18:49:54Z")

</div>

While developing a new logstash codec plugin, the plugin gets installed successfully. But error occurs while using it.

Steps to replicate:

1. Install logstash 7.6 or pull the code from git and cd to the folder where logstash is:  
In my case:  
`cd /usr/share/logstash`

2. Generate a new codec plugin using the default plugin generator:  
`bin/logstash-plugin generate --type codec --name xyz --path /home/centos/`

3. Go to plugin  
`cd /home/centos/logstash-codec-xyz`

4. Change the gemspec and remove TODO's and build plugin using  
`gem build logstash-codec-xyz.gemspec`

5. Go to logstash folder and install the plugin  
`bin/logstash-plugin install /home/centos/logstash-codec-xyz/ logstash-codec-xyz-x.y.z.gem`

6. Using the plugin  
`bin/logstash -e 'input { stdin{ codec => xyz{}} } output {stdout { codec => rubydebug }}'`

Following is the error trace:

```
Thread.exclusive is deprecated, use Thread::Mutex
WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console
[WARN] 2020-03-02 00:15:38.879 [LogStash::Runner] multilocal - Ignoring the 'pipelines.yml' file because modules or command line options are specified
[INFO] 2020-03-02 00:15:38.900 [LogStash::Runner] runner - Starting Logstash {"logstash.version"=>"7.5.2"}
[INFO] 2020-03-02 00:15:42.203 [Converge PipelineAction::Create<main>] Reflections - Reflections took 63 ms to scan 1 urls, producing 20 keys and 40 values
[INFO] 2020-03-02 00:15:42.458 [Converge PipelineAction::Create<main>] xyz - Using version 0.1.x codec plugin 'xyz'. This plugin isn't well supported by the community and likely has no maintainer.
[ERROR] 2020-03-02 00:15:42.553 [Converge PipelineAction::Create<main>] agent - Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main, :exception=>"Java::JavaLang::IllegalStateException", :message=>"Unable to configure plugins: (NameError) uninitialized constant LogStash::Codecs::Line", :backtrace=>["org.logstash.config.ir.CompiledPipeline.<init>(CompiledPipeline.java:119)", "org.logstash.execution.JavaBasePipelineExt.initialize(JavaBasePipelineExt.java:60)", "org.logstash.execution.JavaBasePipelineExt$INVOKER$i$1$0$initialize.call(JavaBasePipelineExt$INVOKER$i$1$0$initialize.gen)", "org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:837)", "org.jruby.ir.runtime.IRRuntimeHelpers.instanceSuper(IRRuntimeHelpers.java:1156)", "org.jruby.ir.runtime.IRRuntimeHelpers.instanceSuperSplatArgs(IRRuntimeHelpers.java:1143)", "org.jruby.ir.targets.InstanceSuperInvokeSite.invoke(InstanceSuperInvokeSite.java:39)", "usr.share.logstash.logstash_minus_core.lib.logstash.java_pipeline.RUBY$method$initialize$0(/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:27)", "org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:91)", "org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:90)", "org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:332)", "org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:86)", "org.jruby.RubyClass.newInstance(RubyClass.java:915)", "org.jruby.RubyClass$INVOKER$i$newInstance.call(RubyClass$INVOKER$i$newInstance.gen)", "org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:183)", "usr.share.logstash.logstash_minus_core.lib.logstash.pipeline_action.create.RUBY$method$execute$0(/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/create.rb:36)", "usr.share.logstash.logstash_minus_core.lib.logstash.pipeline_action.create.RUBY$method$execute$0$ __VARARGS__ (/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/create.rb)", "org.jruby.internal.runtime.methods.CompiledIRMethod.call(CompiledIRMethod.java:91)", "org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:90)", "org.jruby.ir.targets.InvokeSite.invoke(InvokeSite.java:183)", "usr.share.logstash.logstash_minus_core.lib.logstash.agent.RUBY$block$converge_state$2(/usr/share/logstash/logstash-core/lib/logstash/agent.rb:326)", "org.jruby.runtime.CompiledIRBlockBody.callDirect(CompiledIRBlockBody.java:136)", "org.jruby.runtime.IRBlockBody.call(IRBlockBody.java:77)", "org.jruby.runtime.Block.call(Block.java:129)", "org.jruby.RubyProc.call(RubyProc.java:295)", "org.jruby.RubyProc.call(RubyProc.java:274)", "org.jruby.RubyProc.call(RubyProc.java:270)", "org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:105)", "java.lang.Thread.run(Thread.java:748)"]}
warning: thread "Converge PipelineAction::Create<main>" terminated with exception (report_on_exception is true):
LogStash::Error: Don't know how to handle `Java::JavaLang::IllegalStateException` for `PipelineAction::Create<main>`
          create at org/logstash/execution/ConvergeResultExt.java:109
             add at org/logstash/execution/ConvergeResultExt.java:37
  converge_state at /usr/share/logstash/logstash-core/lib/logstash/agent.rb:339
[ERROR] 2020-03-02 00:15:42.569 [Agent thread] agent - An exception happened when converging configuration {:exception=>LogStash::Error, :message=>"Don't know how to handle `Java::JavaLang::IllegalStateException` for `PipelineAction::Create<main>`", :backtrace=>["org/logstash/execution/ConvergeResultExt.java:109:in `create'", "org/logstash/execution/ConvergeResultExt.java:37:in `add'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:339:in `block in converge_state'"]}
[FATAL] 2020-03-02 00:15:42.663 [LogStash::Runner] runner - An unexpected error occurred! {:error=>#<LogStash::Error: Don't know how to handle `Java::JavaLang::IllegalStateException` for `PipelineAction::Create<main>`>, :backtrace=>["org/logstash/execution/ConvergeResultExt.java:109:in `create'", "org/logstash/execution/ConvergeResultExt.java:37:in `add'", "/usr/share/logstash/logstash-core/lib/logstash/agent.rb:339:in `block in converge_state'"]}
[ERROR] 2020-03-02 00:15:42.849 [LogStash::Runner] Logstash - java.lang.IllegalStateException: Logstash stopped processing because of an error: (SystemExit) exit

```

Any help would be great! thanks.

---

<div class="post-metadata">

**Author:** ![i-mohit-a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/i-mohit-a/32/52975_2.png) [@i-mohit-a](https://discuss.elastic.co/u/i-mohit-a)\
**Post date:** [March 3, 2020, 12:59am UTC](https://discuss.elastic.co/t/logstash-new-codec-plugin-fails-while-using/221756/2 "2020-03-03T00:59:20Z")

</div>

I think I have figured out the error:  
Initially, I started looking into java error but the error is not in java, i.e, it is not `Java::JavaLang::IllegalStateException`. The actual error is in ruby with the message `:message=>"Unable to configure plugins: (NameError) uninitialized constant LogStash::Codecs::Line"`. The error is not because of uninitialization, but because of a line missing in the main file, xyz.rb. I figured it out by comparing the code with the code in the [documentation](https://www.elastic.co/guide/en/logstash/current/codec-new-plugin.html#_see_what_your_plugin_looks_like_2).

It can be fixed by adding `require "logstash/codecs/line"` at the top of the file. This works fine after building and installing the gem.

---

<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:** [March 31, 2020, 1:13am UTC](https://discuss.elastic.co/t/logstash-new-codec-plugin-fails-while-using/221756/3 "2020-03-31T01:13:42Z")

</div>

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