This repository has been archived on 2024-04-06. You can view files and clone it, but cannot push or open issues or pull requests.
core-old/internal/tw/parse_error.go
Dawid Wysokiński 5e9399a3d0
All checks were successful
continuous-integration/drone/push Build is passing
feat: add EnnoblementConsumer (#38)
Reviewed-on: twhelp/core#38
2022-08-21 05:19:17 +00:00

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
}