Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
CSV Idiomatic Errors (#323)
Browse files Browse the repository at this point in the history
* Changed errors in csv operator to have lowercase first word to be idiomatic

Signed-off-by: Corbin Phelps <[email protected]>

* Removed fmt.Errorf in csv for errors that did not require formatting

Signed-off-by: Corbin Phelps <[email protected]>
  • Loading branch information
cpheps authored Dec 20, 2021
1 parent d79bfca commit fa36116
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions operator/builtin/parser/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package csv
import (
"context"
csvparser "encoding/csv"
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -52,21 +53,21 @@ func (c CSVParserConfig) Build(context operator.BuildContext) ([]operator.Operat
}

if c.Header == "" {
return nil, fmt.Errorf("Missing required field 'header'")
return nil, errors.New("missing required field 'header'")
}

if c.FieldDelimiter == "" {
c.FieldDelimiter = ","
}

if len([]rune(c.FieldDelimiter)) != 1 {
return nil, fmt.Errorf("Invalid 'delimiter': '%s'", c.FieldDelimiter)
return nil, fmt.Errorf("invalid 'delimiter': '%s'", c.FieldDelimiter)
}

fieldDelimiter := []rune(c.FieldDelimiter)[0]

if !strings.Contains(c.Header, c.FieldDelimiter) {
return nil, fmt.Errorf("missing field delimiter in header")
return nil, errors.New("missing field delimiter in header")
}

numFields := len(strings.Split(c.Header, c.FieldDelimiter))
Expand Down
2 changes: 1 addition & 1 deletion operator/builtin/parser/csv/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestCSVParserBuildFailureInvalidDelimiter(t *testing.T) {
cfg.FieldDelimiter = ";;"
_, err := cfg.Build(testutil.NewBuildContext(t))
require.Error(t, err)
require.Contains(t, err.Error(), "Invalid 'delimiter': ';;'")
require.Contains(t, err.Error(), "invalid 'delimiter': ';;'")
}

func TestCSVParserByteFailure(t *testing.T) {
Expand Down

0 comments on commit fa36116

Please sign in to comment.