chore(cmd/influx/write): improve error reporting
parent
9e7570a64a
commit
2881fce68d
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue