Skip to content

Commit 712f3df

Browse files
committed
Add Unwrap to NumError
1 parent b38be35 commit 712f3df

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/strconv/atoi.go

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func (e *NumError) Error() string {
3131
return "strconv." + e.Func + ": " + "parsing " + Quote(e.Num) + ": " + e.Err.Error()
3232
}
3333

34+
func (e *NumError) Unwrap() error { return e.Err }
35+
3436
func syntaxError(fn, str string) *NumError {
3537
return &NumError{fn, str, ErrSyntax}
3638
}

src/strconv/atoi_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,13 @@ func TestNumError(t *testing.T) {
592592
}
593593
}
594594

595+
func TestNumErrorUnwrap(t *testing.T) {
596+
err := &NumError{Err: ErrSyntax}
597+
if !errors.Is(err, ErrSyntax) {
598+
t.Error("errors.Is failed, wanted success")
599+
}
600+
}
601+
595602
func BenchmarkParseInt(b *testing.B) {
596603
b.Run("Pos", func(b *testing.B) {
597604
benchmarkParseInt(b, 1)

0 commit comments

Comments
 (0)