From: Sergey Matveev Date: Fri, 11 Jul 2025 10:14:23 +0000 (+0300) Subject: FormatErr X-Git-Tag: v3.0.0^0 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=gorecfile.git FormatErr --- diff --git a/r.go b/r.go index 4f88447..4b09cd0 100644 --- a/r.go +++ b/r.go @@ -17,7 +17,6 @@ package recfile import ( "bufio" - "errors" "io" "strings" ) @@ -26,6 +25,12 @@ type Reader struct { scanner *bufio.Scanner } +type FormatErr string + +func (err FormatErr) Error() string { + return string(err) +} + // Create Reader for iterating through the records. It uses // bufio.Scanner, so can read more than currently parsed records take. func NewReader(r io.Reader) *Reader { @@ -118,7 +123,7 @@ func (r *Reader) Next() ([]Field, error) { name, line = getKeyValue(text) if name == "" { - return fields, errors.New("invalid field format") + return fields, FormatErr("invalid field format") } if len(line) > 0 && line[len(line)-1] == '\\' { @@ -129,7 +134,7 @@ func (r *Reader) Next() ([]Field, error) { } } if continuation { - return fields, errors.New("left continuation") + return fields, FormatErr("left continuation") } if len(lines) > 0 { fields = append(fields, Field{name, strings.Join(lines, "")})