chore(cmd/influx/write): improve error reporting

pull/17398/head
Pavel Zavora 2020-03-27 08:20:27 +01:00
parent 9e7570a64a
commit 2881fce68d
3 changed files with 23 additions and 7 deletions

View File

@ -15,12 +15,7 @@ type CsvLineError struct {
}
func (e CsvLineError) Error() string {
switch err := e.Err.(type) {
case CsvColumnError:
return fmt.Sprintf("line %d, column '%s': %v", e.Line, err.Column, err)
default:
return fmt.Sprintf("line %d: %v", e.Line, e.Err)
}
return fmt.Sprintf("line %d: %v", e.Line, e.Err)
}
type lineReader struct {

View File

@ -1,6 +1,7 @@
package write
import (
"errors"
"io"
"strings"
"testing"
@ -75,3 +76,23 @@ func Test_CsvToProtocolLines_success(t *testing.T) {
}
}
}
// Test_CsvLineError checks formating of line errors
func Test_CsvLineError(t *testing.T) {
var tests = []struct {
err CsvLineError
value string
}{
{
CsvLineError{Line: 1, Err: errors.New("cause")},
"line 1: cause",
},
{
CsvLineError{Line: 2, Err: CsvColumnError{"a", errors.New("cause")}},
"line 2: column 'a': cause",
},
}
for _, test := range tests {
require.Equal(t, test.value, test.err.Error())
}
}

View File

@ -112,7 +112,7 @@ func toTypedValue(val string, dataType string) (interface{}, error) {
case base64BinaryDataType:
return base64.StdEncoding.DecodeString(val)
default:
return nil, fmt.Errorf("value '%s' has unsupported data type '%s'", val, dataType)
return nil, fmt.Errorf("unsupported data type '%s'", dataType)
}
}