From 59d4c539d1fddbc8cfa94c7b1e67359b5230c788 Mon Sep 17 00:00:00 2001 From: Conor Broderick Date: Wed, 6 Dec 2017 15:39:06 +0000 Subject: [PATCH] Added rule name to rule error for easier debugging (#3549) --- pkg/rulefmt/rulefmt.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/rulefmt/rulefmt.go b/pkg/rulefmt/rulefmt.go index b76137283..e8e072f74 100644 --- a/pkg/rulefmt/rulefmt.go +++ b/pkg/rulefmt/rulefmt.go @@ -26,13 +26,14 @@ import ( // Error represents semantical errors on parsing rule groups. type Error struct { - Group string - Rule int - Err error + Group string + Rule int + RuleName string + Err error } func (err *Error) Error() string { - return errors.Wrapf(err.Err, "group %q, rule %d", err.Group, err.Rule).Error() + return errors.Wrapf(err.Err, "group %q, rule %d, %q", err.Group, err.Rule, err.RuleName).Error() } // RuleGroups is a set of rule groups that are typically exposed in a file. @@ -67,10 +68,17 @@ func (g *RuleGroups) Validate() (errs []error) { for i, r := range g.Rules { for _, err := range r.Validate() { + var ruleName string + if r.Alert != "" { + ruleName = r.Alert + } else { + ruleName = r.Record + } errs = append(errs, &Error{ - Group: g.Name, - Rule: i, - Err: err, + Group: g.Name, + Rule: i, + RuleName: ruleName, + Err: err, }) } }