Browse Source

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 years ago
parent
commit
1ebb73c60e
No account linked to committer's email address
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      profile/proto.go

+ 5
- 2
profile/proto.go View File

33
 
33
 
34
 package profile
34
 package profile
35
 
35
 
36
-import "errors"
36
+import (
37
+	"errors"
38
+	"fmt"
39
+)
37
 
40
 
38
 type buffer struct {
41
 type buffer struct {
39
 	field int // field tag
42
 	field int // field tag
235
 		b.u64 = uint64(le32(data[:4]))
238
 		b.u64 = uint64(le32(data[:4]))
236
 		data = data[4:]
239
 		data = data[4:]
237
 	default:
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
 	return data, nil
244
 	return data, nil