From 5fe2035927bc9fac8a375a96d9ef47735c10fba4 Mon Sep 17 00:00:00 2001 From: Daniel Martí Date: Fri, 7 Apr 2023 18:53:49 +0100 Subject: internal/profile: actually return errors in postDecode As spotted by staticcheck, the body did keep track of errors by sharing a single err variable, but its last value was never used as the function simply finished by returning nil. To prevent postDecode from erroring on empty profiles, which breaks TestEmptyProfile, add a check at the top of the function. Update the runtime/pprof test accordingly, since the default units didn't make sense for an empty profile anyway. Change-Id: I188cd8337434adf9169651ab5c914731b8b20f39 Reviewed-on: https://go-review.googlesource.com/c/go/+/483137 Reviewed-by: David Chase Reviewed-by: Michael Pratt Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI --- src/runtime/pprof/proto_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/runtime') diff --git a/src/runtime/pprof/proto_test.go b/src/runtime/pprof/proto_test.go index f788b167da..e1a7f2306d 100644 --- a/src/runtime/pprof/proto_test.go +++ b/src/runtime/pprof/proto_test.go @@ -64,13 +64,9 @@ func TestConvertCPUProfileEmpty(t *testing.T) { } // Expected PeriodType and SampleType. - periodType := &profile.ValueType{Type: "cpu", Unit: "nanoseconds"} - sampleType := []*profile.ValueType{ - {Type: "samples", Unit: "count"}, - {Type: "cpu", Unit: "nanoseconds"}, - } + sampleType := []*profile.ValueType{{}, {}} - checkProfile(t, p, 2000*1000, periodType, sampleType, nil, "") + checkProfile(t, p, 2000*1000, nil, sampleType, nil, "") } func f1() { f1() } -- cgit v1.3-5-g9baa