chore(cmd/influx/write): improve error reporting
parent
9e7570a64a
commit
2881fce68d
|
@ -15,12 +15,7 @@ type CsvLineError struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e CsvLineError) Error() string {
|
func (e CsvLineError) Error() string {
|
||||||
switch err := e.Err.(type) {
|
return fmt.Sprintf("line %d: %v", e.Line, e.Err)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type lineReader struct {
|
type lineReader struct {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package write
|
package write
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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:
|
case base64BinaryDataType:
|
||||||
return base64.StdEncoding.DecodeString(val)
|
return base64.StdEncoding.DecodeString(val)
|
||||||
default:
|
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