From d97f2818b47b3e1875d7b217346b61e7e1d49408 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Fri, 11 Jul 2025 13:14:23 +0300 Subject: [PATCH] FormatErr --- r.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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, "")}) -- 2.50.0