Procházet zdrojové kódy

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 před 5 roky
rodič
revize
d6d2dc122c
No account linked to committer's email address
2 změnil soubory, kde provedl 10 přidání a 4 odebrání
  1. 6
    4
      profile/profile.go
  2. 4
    0
      profile/profile_test.go

+ 6
- 4
profile/profile.go Zobrazit soubor

@@ -398,10 +398,12 @@ func (p *Profile) CheckValid() error {
398 398
 			}
399 399
 		}
400 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 Zobrazit soubor

@@ -175,6 +175,10 @@ func TestCheckValid(t *testing.T) {
175 175
 			mutateFn: func(p *Profile) { p.Function[0] = nil },
176 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 183
 		t.Run(tc.wantErr, func(t *testing.T) {
180 184
 			p := p.Copy()