Skip to content

Commit d1ac44e

Browse files
committed
fix: do not wrap io.EOF in errd.Wrap
Per the Go documentation, io.EOF must not be wrapped because callers test for it using ==. The errd.Wrap helper wraps all non-nil errors, including io.EOF, causing functions like Conn.reader to return wrapped EOF errors that break standard EOF checks. Skip wrapping when the error is io.EOF. Fixes #561
1 parent d099e16 commit d1ac44e

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

internal/errd/wrap.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ package errd
22

33
import (
44
"fmt"
5+
"io"
56
)
67

78
// Wrap wraps err with fmt.Errorf if err is non nil.
89
// Intended for use with defer and a named error return.
910
// Inspired by https://github.com/golang/go/issues/32676.
11+
//
12+
// io.EOF is never wrapped because callers test for it with ==.
1013
func Wrap(err *error, f string, v ...any) {
11-
if *err != nil {
14+
if *err != nil && *err != io.EOF {
1215
*err = fmt.Errorf(f+": %w", append(v, *err)...)
1316
}
1417
}

0 commit comments

Comments
 (0)