Skip to content

Commit a27c4d0

Browse files
authored
fix: fix errors suffix detection (#125)
2 parents 87fe3bf + 90ea2e0 commit a27c4d0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

errors/fmt.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ func newErrorf(c *errorfConfig) func(format string, a ...interface{}) error {
5656
suffixW = ": %w"
5757
)
5858
var (
59-
hasSuffixS = strings.Contains(format, suffixS)
60-
hasSuffixV = strings.Contains(format, suffixV)
61-
hasSuffixPlusV = strings.Contains(format, suffixPlusV)
62-
hasSuffixSharpV = strings.Contains(format, suffixSharpV)
63-
hasSuffixW = strings.Contains(format, suffixW)
59+
hasSuffixS = strings.HasSuffix(format, suffixS)
60+
hasSuffixV = strings.HasSuffix(format, suffixV)
61+
hasSuffixPlusV = strings.HasSuffix(format, suffixPlusV)
62+
hasSuffixSharpV = strings.HasSuffix(format, suffixSharpV)
63+
hasSuffixW = strings.HasSuffix(format, suffixW)
6464
)
6565

6666
if !hasSuffixS && !hasSuffixV && !hasSuffixPlusV && !hasSuffixSharpV && !hasSuffixW {

errors/fmt_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ func TestErrorf(t *testing.T) {
196196
}
197197
t.Logf("ℹ️: [%s]:\nError():\n%s\n", t.Name(), actual.Error())
198198
})
199+
200+
t.Run("success,SuffixDetectionLogic", func(t *testing.T) {
201+
actual := Errorf("%s %s: %w", "my", "test", io.ErrUnexpectedEOF)
202+
expect := io.ErrUnexpectedEOF
203+
if !errors.Is(actual, io.ErrUnexpectedEOF) {
204+
t.Errorf("❌: [%s]: [%%s]:\n[EXPECT]:\n%v\n[ACTUAL]:\n%v\n", t.Name(), expect, actual)
205+
}
206+
})
199207
}
200208

201209
func Test_wrapError_FormatError(t *testing.T) {

0 commit comments

Comments
 (0)