Browse Source

profile.CheckValid should return an error if location has a line with empty function (#517)

* Check if location has a line with empty function

* Include context in the error message that will help triage the error
Dmitry Labutin 5 years ago
parent
commit
d6d2dc122c
No account linked to committer's email address
2 changed files with 10 additions and 4 deletions
  1. 6
    4
      profile/profile.go
  2. 4
    0
      profile/profile_test.go

+ 6
- 4
profile/profile.go View File

398
 			}
398
 			}
399
 		}
399
 		}
400
 		for _, ln := range l.Line {
400
 		for _, ln := range l.Line {
401
-			if f := ln.Function; f != nil {
402
-				if f.ID == 0 || functions[f.ID] != f {
403
-					return fmt.Errorf("inconsistent function %p: %d", f, f.ID)
404
-				}
401
+			f := ln.Function
402
+			if f == nil {
403
+				return fmt.Errorf("location id: %d has a line with nil function", l.ID)
404
+			}
405
+			if f.ID == 0 || functions[f.ID] != f {
406
+				return fmt.Errorf("inconsistent function %p: %d", f, f.ID)
405
 			}
407
 			}
406
 		}
408
 		}
407
 	}
409
 	}

+ 4
- 0
profile/profile_test.go View File

175
 			mutateFn: func(p *Profile) { p.Function[0] = nil },
175
 			mutateFn: func(p *Profile) { p.Function[0] = nil },
176
 			wantErr:  "profile has nil function",
176
 			wantErr:  "profile has nil function",
177
 		},
177
 		},
178
+		{
179
+			mutateFn: func(p *Profile) { p.Location[0].Line = append(p.Location[0].Line, Line{}) },
180
+			wantErr:  "has a line with nil function",
181
+		},
178
 	} {
182
 	} {
179
 		t.Run(tc.wantErr, func(t *testing.T) {
183
 		t.Run(tc.wantErr, func(t *testing.T) {
180
 			p := p.Copy()
184
 			p := p.Copy()