Dawid Wysokiński
5e9399a3d0
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: twhelp/core#38
43 lines
724 B
Go
43 lines
724 B
Go
package tw
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
recordLenLimit = 100
|
|
)
|
|
|
|
type ParseError struct {
|
|
record []string
|
|
field string
|
|
err error
|
|
}
|
|
|
|
func NewParseError(err error, record []string, field string) ParseError {
|
|
return ParseError{
|
|
err: err,
|
|
record: record,
|
|
field: field,
|
|
}
|
|
}
|
|
func (e ParseError) Error() string {
|
|
recordStr := strings.Join(e.record, ",")
|
|
if len(recordStr) > recordLenLimit {
|
|
recordStr = recordStr[0:recordLenLimit-3] + "..."
|
|
}
|
|
return "parse error (field=" + e.field + " record=" + recordStr + "): " + e.err.Error()
|
|
}
|
|
|
|
func (e ParseError) Field() string {
|
|
return e.field
|
|
}
|
|
|
|
func (e ParseError) Record() []string {
|
|
return e.record
|
|
}
|
|
|
|
func (e ParseError) Unwrap() error {
|
|
return e.err
|
|
}
|