parser_csv: skip empty or unparseable lines#5355
Merged
Merged
Conversation
Contributor
Author
|
Simple reproduction: |
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
Watson1978
added a commit
that referenced
this pull request
May 17, 2026
…5359) **Which issue(s) this PR fixes**: Backport #5355 Fixes # **What this PR does / why we need it**: This PR fixes an issue in `parser_csv` where processing an empty line causes a `TypeError`. When `parser_csv` receives an empty line, `CSV.parse_line` returns `nil`. Currently, passing this `nil` value to `Array#zip` throws a `TypeError: wrong argument type NilClass (must respond to :each)`. ### Reproduce config: ``` <source> @type tail path "#{File.expand_path '~/tmp/fluentd/test.csv'}" tag test.csv read_from_head true <parse> @type csv keys k1,k2,k3 </parse> </source> <match test.csv> @type stdout </match> ``` Prepare input data: ``` $ echo "A,B,C" > ~/tmp/fluentd/test.csv $ echo "" >> ~/tmp/fluentd/test.csv $ echo "D,E,F" >> ~/tmp/fluentd/test.csv ``` Result of before changing: ``` 2026-05-09 17:23:14 +0900 [info]: #0 following tail of /home/watson/tmp/fluentd/test.csv 2026-05-09 17:23:14 +0900 [warn]: #0 invalid line found 2026-05-09 17:23:14 +0900 [warn]: #0 this parameter is highly recommended to save the position to resume tailing. 2026-05-09 17:23:14 +0900 [info]: #0 starting fluentd worker pid=41671 ppid=41646 worker=0 2026-05-09 17:23:14 +0900 [info]: #0 following tail of /home/watson/tmp/fluentd/test.csv 2026-05-09 17:23:14 +0900 [warn]: #0 invalid line found file="/home/watson/tmp/fluentd/test.csv" line="" error="wrong argument type NilClass (must respond to :each)" 2026-05-09 17:23:14.692710744 +0900 test.csv: {"k1":"A","k2":"B","k3":"C"} 2026-05-09 17:23:14.692801343 +0900 test.csv: {"k1":"D","k2":"E","k3":"F"} 2026-05-09 17:23:14 +0900 [info]: #0 fluentd worker is now running worker=0 ``` **Docs Changes**: N/A **Release Note**: * parser_csv: skip empty or unparseable lines Signed-off-by: Shizuo Fujita <fujita@clear-code.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Shizuo Fujita <fujita@clear-code.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) this PR fixes:
Fixes #
What this PR does / why we need it:
This PR fixes an issue in
parser_csvwhere processing an empty line causes aTypeError.When
parser_csvreceives an empty line,CSV.parse_linereturnsnil.Currently, passing this
nilvalue toArray#zipthrows aTypeError: wrong argument type NilClass (must respond to :each).Reproduce
config:
Prepare input data:
Result of before changing:
Docs Changes:
N/A
Release Note: