# Error reading empty line from CSV file with CSV codec

**URL:** https://discuss.elastic.co/t/error-reading-empty-line-from-csv-file-with-csv-codec/351635
**Category:** Logstash
**Created:** [January 23, 2024, 2:14pm UTC](https://discuss.elastic.co/t/error-reading-empty-line-from-csv-file-with-csv-codec/351635 "2024-01-23T14:14:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tsegars](https://avatars.discourse-cdn.com/v4/letter/t/77aa72/32.png) [@tsegars](https://discuss.elastic.co/u/tsegars)
#### Post date: [January 23, 2024, 2:14pm UTC](https://discuss.elastic.co/t/error-reading-empty-line-from-csv-file-with-csv-codec/351635/1 "2024-01-23T14:14:46Z")

</div>

My input CSV files will have empty lines interspersed in them. The CSV codec decoder generates the following error when encountering an empty line:

[ERROR][filewatch.tailmode.handlers.grow][main][62dd5eb2b6763ff5522ed5480a076813eac7068008e52a3c7908c2befa19642e] controlled\_read general error reading {:path=\>"/opt/logstash/test/data/status-monitoring-hyosung-proto-TEST.csv", :exception=\>NoMethodError, :message=\>"undefined method `each\_with\_index' for nil:NilClass", :backtrace=\>

After many attempts to get the configuration right, I stripped the config down to the bare minimum, but get the same error. Here's the stripped down, minimal config:

```auto
input {
  file {
    mode => "tail"
    path => ["/opt/logstash/test/data/status-monitoring-hyosung-proto-TEST.csv"]
    start_position => "beginning"
    sincedb_path => ["/tmp/logstash-output-jdbc-proto-sincedb"]
    codec => csv {
    }
  }
}
output {
  stdout {}
}

```

If I remove the csv codec stanza from the config, logstash ingests the csv file without issue. Here's the stripped down csv file I'm using for troubleshooting:

```auto
date,time,terminalID
2024-01-21,00:00:05,MP002001

2024-01-21,00:00:14,MP002002

2024-01-21,00:00:16,MP002003

```

Is it a known issue that the csv codec decoder cannot handle empty lines, or am I missing some configuration setting for dealing with empty lines?

---

<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: [January 23, 2024, 5:54pm UTC](https://discuss.elastic.co/t/error-reading-empty-line-from-csv-file-with-csv-codec/351635/2 "2024-01-23T17:54:51Z")

</div>

The codec [cannot handle](https://github.com/logstash-plugins/logstash-codec-csv/blob/ce2456090671b9852d42bd6896f69b80e668e395/lib/logstash/codecs/csv.rb#L148) empty rows. The filter has a [skip\_empty\_rows](https://github.com/logstash-plugins/logstash-filter-csv/blob/30b2c232293f9b0e11bdc36938c32b15731de3e8/lib/logstash/filters/csv.rb#L154) option that tags blank lines. So you use a csv filter instead of a csv codec.

---

<div class="post-metadata">

### Author: ![tsegars](https://avatars.discourse-cdn.com/v4/letter/t/77aa72/32.png) [@tsegars](https://discuss.elastic.co/u/tsegars)
#### Post date: [January 23, 2024, 7:59pm UTC](https://discuss.elastic.co/t/error-reading-empty-line-from-csv-file-with-csv-codec/351635/3 "2024-01-23T19:59:08Z")

</div>

Switching to a csv filter was exactly what I needed.  
Thank you, Badger.

---

<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: [February 20, 2024, 7:59pm UTC](https://discuss.elastic.co/t/error-reading-empty-line-from-csv-file-with-csv-codec/351635/4 "2024-02-20T19:59:46Z")

</div>

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