From a82c7756b39a6ec2c29e8f1bd60f2d73021e5936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Tremblay?= <1619947+marctrem@users.noreply.github.com> Date: Wed, 16 Oct 2024 13:38:04 +0000 Subject: [PATCH] introduce ErrLineTruncated --- io/linereader/err_line_truncated.go | 11 +++++++++++ io/linereader/linereader.go | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 io/linereader/err_line_truncated.go diff --git a/io/linereader/err_line_truncated.go b/io/linereader/err_line_truncated.go new file mode 100644 index 0000000..a46a73e --- /dev/null +++ b/io/linereader/err_line_truncated.go @@ -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) +} diff --git a/io/linereader/linereader.go b/io/linereader/linereader.go index b0f2174..6de5ea6 100644 --- a/io/linereader/linereader.go +++ b/io/linereader/linereader.go @@ -2,7 +2,6 @@ package linereader import ( "bytes" - "errors" "io" armath "github.com/asymmetric-research/go-commons/math" @@ -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 }