diff --git a/pkg/stanza/operator/parser/csv/csv.go b/pkg/stanza/operator/parser/csv/csv.go index 58ec883584b4..7433123261ac 100644 --- a/pkg/stanza/operator/parser/csv/csv.go +++ b/pkg/stanza/operator/parser/csv/csv.go @@ -196,7 +196,7 @@ func generateParseFunc(headers []string, fieldDelimiter rune, lazyQuotes bool) p parsedValues := make(map[string]interface{}) if len(joinedLine) != len(headers) { - return nil, errors.New("wrong number of fields") + return nil, fmt.Errorf("wrong number of fields: expected %d, found %d", len(headers), len(joinedLine)) } for i, val := range joinedLine { diff --git a/pkg/stanza/operator/parser/csv/csv_test.go b/pkg/stanza/operator/parser/csv/csv_test.go index de9bb55d8bb4..53e2efb7d347 100644 --- a/pkg/stanza/operator/parser/csv/csv_test.go +++ b/pkg/stanza/operator/parser/csv/csv_test.go @@ -65,14 +65,14 @@ func TestParserByteFailure(t *testing.T) { parser := newTestParser(t) _, err := parser.parse([]byte("invalid")) require.Error(t, err) - require.Contains(t, err.Error(), "wrong number of fields") + require.Contains(t, err.Error(), "wrong number of fields: expected 3, found 1") } func TestParserStringFailure(t *testing.T) { parser := newTestParser(t) _, err := parser.parse("invalid") require.Error(t, err) - require.Contains(t, err.Error(), "wrong number of fields") + require.Contains(t, err.Error(), "wrong number of fields: expected 3, found 1") } func TestParserInvalidType(t *testing.T) { diff --git a/unreleased/pkg-stanza-csv-err.yaml b/unreleased/pkg-stanza-csv-err.yaml new file mode 100755 index 000000000000..1500759e0b3a --- /dev/null +++ b/unreleased/pkg-stanza-csv-err.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: "`filelog`, `journald`, `syslog`, `tcplog`, `udplog`, `windowseventlog` receivers" + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Enhance error message when csv_parser finds unexpected number of fields + +# One or more tracking issues related to the change +issues: [13427] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: