File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package errors
66
77import (
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.
4142func 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 )}
Original file line number Diff line number Diff line change @@ -483,3 +483,9 @@ func (e fmtTwiceErr) GoString() string {
483483type panicValue struct {}
484484
485485func (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+ }
You can’t perform that action at this time.
0 commit comments