]> Cypherpunks repositories - gorecfile.git/commitdiff
FormatErr master v3.0.0
authorSergey Matveev <stargrave@stargrave.org>
Fri, 11 Jul 2025 10:14:23 +0000 (13:14 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 11 Jul 2025 10:14:23 +0000 (13:14 +0300)
r.go

diff --git a/r.go b/r.go
index 4f88447570054a21d8504818d47f680e018864e8..4b09cd01ffb41916e0fcfa14ed2d0b13c91079a0 100644 (file)
--- 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, "")})