Skip to content

Commit da2567e

Browse files
committed
feat: add fallback for Errorf
1 parent 0633115 commit da2567e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

format.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package errors
66

77
import (
88
"fmt"
9+
"strings"
910
)
1011

1112
// A Formatter formats error messages.
@@ -39,7 +40,7 @@ type Printer interface {
3940

4041
// Errorf creates new error with format.
4142
func Errorf(format string, a ...interface{}) error {
42-
if !Trace() {
43+
if !Trace() || strings.Contains(format, "%w") {
4344
return fmt.Errorf(format, a...)
4445
}
4546
return &errorString{fmt.Sprintf(format, a...), Caller(1)}

format_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,9 @@ func (e fmtTwiceErr) GoString() string {
483483
type panicValue struct{}
484484

485485
func (panicValue) String() string { panic("panic") }
486+
487+
func TestFormatError(t *testing.T) {
488+
if !errors.Is(errors.Errorf("foo: %w", io.EOF), io.EOF) {
489+
t.Error("fallback expected")
490+
}
491+
}

0 commit comments

Comments
 (0)