Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/errd/wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ 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 the Go convention requires
// callers to test for EOF using ==, not errors.Is.
Comment on lines +12 to +13
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems backwards. Go convention does not require callers to do this. The convention asks implementers to return io.EOF due to backwards compatibility and the stdlib implementation being frozen.

Callers should absolutely use errors.Is, it's the modern way.

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)...)
}
}
Loading