浏览代码

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 年前
父节点
当前提交
1ebb73c60e
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5
    2
      profile/proto.go

+ 5
- 2
profile/proto.go 查看文件

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