From 8197992c3034461701d1c89643493d84ad50d10b Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Thu, 3 Oct 2024 08:56:08 +0100 Subject: [PATCH] Fix panics in rule/duplicate --- docs/changelog.md | 1 + internal/checks/rule_duplicate.go | 3 +++ internal/checks/rule_duplicate_test.go | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index f13c691f..a569f035 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,7 @@ - Reverted `Fixed colored output on some environments - #1106` change as it was breaking GitHub report comments. +- Fixed panics in [rule/duplicate](checks/rule/duplicate.md) check. ## v0.65.3 diff --git a/internal/checks/rule_duplicate.go b/internal/checks/rule_duplicate.go index 4d75b353..0520d745 100644 --- a/internal/checks/rule_duplicate.go +++ b/internal/checks/rule_duplicate.go @@ -53,6 +53,9 @@ func (c RuleDuplicateCheck) Check(ctx context.Context, path discovery.Path, rule if entry.State == discovery.Removed { continue } + if entry.PathError != nil { + continue + } if entry.Rule.Error.Err != nil { continue } diff --git a/internal/checks/rule_duplicate_test.go b/internal/checks/rule_duplicate_test.go index e254a939..b0fe4cca 100644 --- a/internal/checks/rule_duplicate_test.go +++ b/internal/checks/rule_duplicate_test.go @@ -1,12 +1,14 @@ package checks_test import ( + "errors" "fmt" "regexp" "testing" "time" "github.com/cloudflare/pint/internal/checks" + "github.com/cloudflare/pint/internal/discovery" "github.com/cloudflare/pint/internal/parser" "github.com/cloudflare/pint/internal/promapi" ) @@ -32,13 +34,16 @@ func TestRuleDuplicateCheck(t *testing.T) { problems: noProblems, }, { - description: "ignores alerting rules", - content: "- alert: foo\n expr: up == 0\n", + description: "ignores entries with path errors", + content: "- record: foo\n expr: up == 0\n", checker: func(prom *promapi.FailoverGroup) checks.RuleChecker { return checks.NewRuleDuplicateCheck(prom) }, prometheus: newSimpleProm, problems: noProblems, + entries: []discovery.Entry{ + {PathError: errors.New("Mock error")}, + }, }, { description: "ignores self",