From d1ac44e9e1e5245759126934985b6f1aa1c2a878 Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Thu, 16 Apr 2026 09:12:57 +0800 Subject: [PATCH] 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 --- internal/errd/wrap.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/errd/wrap.go b/internal/errd/wrap.go index c80d0a65..cf5af9f7 100644 --- a/internal/errd/wrap.go +++ b/internal/errd/wrap.go @@ -2,13 +2,16 @@ package errd import ( "fmt" + "io" ) // Wrap wraps err with fmt.Errorf if err is non nil. // Intended for use with defer and a named error return. // Inspired by https://github.com/golang/go/issues/32676. +// +// io.EOF is never wrapped because callers test for it with ==. func Wrap(err *error, f string, v ...any) { - if *err != nil { + if *err != nil && *err != io.EOF { *err = fmt.Errorf(f+": %w", append(v, *err)...) } }