Skip to content

Commit

Permalink
profile.CheckValid should return an error if location has a line with…
Browse files Browse the repository at this point in the history
… empty function (#517)

* Check if location has a line with empty function

* Include context in the error message that will help triage the error
  • Loading branch information
Labutin authored Apr 7, 2020
1 parent 7d83b28 commit d6d2dc1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,12 @@ func (p *Profile) CheckValid() error {
}
}
for _, ln := range l.Line {
if f := ln.Function; f != nil {
if f.ID == 0 || functions[f.ID] != f {
return fmt.Errorf("inconsistent function %p: %d", f, f.ID)
}
f := ln.Function
if f == nil {
return fmt.Errorf("location id: %d has a line with nil function", l.ID)
}
if f.ID == 0 || functions[f.ID] != f {
return fmt.Errorf("inconsistent function %p: %d", f, f.ID)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions profile/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func TestCheckValid(t *testing.T) {
mutateFn: func(p *Profile) { p.Function[0] = nil },
wantErr: "profile has nil function",
},
{
mutateFn: func(p *Profile) { p.Location[0].Line = append(p.Location[0].Line, Line{}) },
wantErr: "has a line with nil function",
},
} {
t.Run(tc.wantErr, func(t *testing.T) {
p := p.Copy()
Expand Down

0 comments on commit d6d2dc1

Please sign in to comment.