From: Ian Lance Taylor Date: Thu, 27 Feb 2020 19:24:24 +0000 (-0800) Subject: runtime/pprof/internal/profile: make error message readable X-Git-Tag: go1.15beta1~987 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2172b229b95f483324825806f692303a0a132762;p=gostls13.git runtime/pprof/internal/profile: make error message readable The error message for an unrecognized type in decodeField was using string(i) for an int type i. It was recently changed (by me) to string(rune(i)), but that just avoided a vet warning without fixing the problem. This CL fixes the problem by using fmt.Errorf. We also change the message to "unknown wire type" to match the master copy of this code in github.com/google/pprof/profile/proto.go. Updates #32479 Change-Id: Ia91ea6d5edbd7cd946225d1ee96bb7623b52bb44 Reviewed-on: https://go-review.googlesource.com/c/go/+/221384 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Emmanuel Odeke --- diff --git a/src/runtime/pprof/internal/profile/proto.go b/src/runtime/pprof/internal/profile/proto.go index 294acfeb92..52cf1ef2b3 100644 --- a/src/runtime/pprof/internal/profile/proto.go +++ b/src/runtime/pprof/internal/profile/proto.go @@ -21,7 +21,10 @@ package profile -import "errors" +import ( + "errors" + "fmt" +) type buffer struct { field int @@ -232,7 +235,7 @@ func decodeField(b *buffer, data []byte) ([]byte, error) { b.u64 = uint64(le32(data[:4])) data = data[4:] default: - return nil, errors.New("unknown type: " + string(rune(b.typ))) + return nil, fmt.Errorf("unknown wire type: %d", b.typ) } return data, nil