Skip to content

Commit

Permalink
Merge pull request #2 from asymmetric-research/marctrem/custom-error-…
Browse files Browse the repository at this point in the history
…line-too-long

Introduce ErrLineTruncated
  • Loading branch information
marctrem authored Oct 16, 2024
2 parents 3b9f188 + a82c775 commit 71a04bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 11 additions & 0 deletions io/linereader/err_line_truncated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package linereader

import "fmt"

type ErrLineTruncated struct {
Discarded int
}

func (e *ErrLineTruncated) Error() string {
return fmt.Sprintf("line truncated (discarded %d bytes)", e.Discarded)
}
3 changes: 1 addition & 2 deletions io/linereader/linereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package linereader

import (
"bytes"
"errors"
"io"

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

0 comments on commit 71a04bf

Please sign in to comment.