Skip to content

Commit

Permalink
Fixing error message for invalid csv field separators
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshaw committed Mar 31, 2024
1 parent 110a5bb commit 8ba91cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ func FromMap(opts map[string]string) (Builder, []Option) {
sep, quote, field = ',', '"', "csv_fieldsep"
}
if s, ok := opts[field]; ok {
if len(s) != 1 {
return newErrEncoder, []Option{withError(ErrInvalidFieldSeparator)}
r := []rune(s)
if len(r) != 1 {
err := ErrInvalidFieldSeparator
if format == "csv" {
err = ErrInvalidCSVFieldSeparator
}
return newErrEncoder, []Option{withError(err)}
}
sep = []rune(s)[0]
sep = r[0]
}
if format != "csv" && opts["fieldsep_zero"] == "on" {
sep = 0
Expand Down
2 changes: 2 additions & 0 deletions tblfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ const (
ErrInvalidTemplate Error = "invalid template"
// ErrInvalidFieldSeparator is the invalid field separator error.
ErrInvalidFieldSeparator Error = "invalid field separator"
// ErrInvalidCSVFieldSeparator is the invalid csv field separator error.
ErrInvalidCSVFieldSeparator Error = "invalid csv field separator"
// ErrInvalidColumnParams is the invalid column params error.
ErrInvalidColumnParams Error = "invalid column params"
// ErrCrosstabResultMustHaveAtLeast3Columns is the crosstab result must
Expand Down

0 comments on commit 8ba91cf

Please sign in to comment.