Bladeren bron

profile: change error message to print string representation of wire type (#514)

The proto write type code stored in buffer stores unprintable values
(e.g. 2 when unmarshalling). The desired output when printing an error
message is the string representation of the integer (i.e. strconv.Itoa),
instead of the current behavior string(int) or string(rune), which
return the utf8 literal corresponding to the integer.

As pointed out by @ianlancetaylor in
https://github.com/google/pprof/commit/4ac0da8#commitcomment-37524728, commit
4ac0da8 preserves the previous incorrect behavior to pass a vet check,
whereas this change prints the desired output.

Updates golang/go#32479.
Akhil Indurti 5 jaren geleden
bovenliggende
commit
1ebb73c60e
No account linked to committer's email address
1 gewijzigde bestanden met toevoegingen van 5 en 2 verwijderingen
  1. 5
    2
      profile/proto.go

+ 5
- 2
profile/proto.go Bestand weergeven

@@ -33,7 +33,10 @@
33 33
 
34 34
 package profile
35 35
 
36
-import "errors"
36
+import (
37
+	"errors"
38
+	"fmt"
39
+)
37 40
 
38 41
 type buffer struct {
39 42
 	field int // field tag
@@ -235,7 +238,7 @@ func decodeField(b *buffer, data []byte) ([]byte, error) {
235 238
 		b.u64 = uint64(le32(data[:4]))
236 239
 		data = data[4:]
237 240
 	default:
238
-		return nil, errors.New("unknown wire type: " + string(rune(b.typ)))
241
+		return nil, fmt.Errorf("unknown wire type: %d", b.typ)
239 242
 	}
240 243
 
241 244
 	return data, nil