]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof/internal/profile: make error message readable
authorIan Lance Taylor <iant@golang.org>
Thu, 27 Feb 2020 19:24:24 +0000 (11:24 -0800)
committerIan Lance Taylor <iant@golang.org>
Sun, 1 Mar 2020 02:22:06 +0000 (02:22 +0000)
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
src/runtime/pprof/internal/profile/proto.go

index 294acfeb92f26ed4fb9009cd938facd39b9cb3bc..52cf1ef2b3b5d0083aed1078fef004f7b4e858e0 100644 (file)
 
 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