Skip to content

Commit 71a04bf

Browse files
authored
Merge pull request #2 from asymmetric-research/marctrem/custom-error-line-too-long
Introduce ErrLineTruncated
2 parents 3b9f188 + a82c775 commit 71a04bf

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

io/linereader/err_line_truncated.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package linereader
2+
3+
import "fmt"
4+
5+
type ErrLineTruncated struct {
6+
Discarded int
7+
}
8+
9+
func (e *ErrLineTruncated) Error() string {
10+
return fmt.Sprintf("line truncated (discarded %d bytes)", e.Discarded)
11+
}

io/linereader/linereader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package linereader
22

33
import (
44
"bytes"
5-
"errors"
65
"io"
76

87
armath "github.com/asymmetric-research/go-commons/math"
@@ -32,7 +31,7 @@ func NewInto(dst *T, reader io.Reader, blockSize uint) {
3231
func (lr *T) Read(dst []byte) (n int, err error) {
3332
n, discarded, err := lr.ReadExtra(dst)
3433
if discarded != 0 {
35-
return n, errors.New("line too long")
34+
return n, &ErrLineTruncated{Discarded: discarded}
3635
}
3736
return n, err
3837
}

0 commit comments

Comments
 (0)