diff --git a/promql/ast.go b/promql/ast.go index 249eab4fa..dba38db3b 100644 --- a/promql/ast.go +++ b/promql/ast.go @@ -306,11 +306,11 @@ func Walk(v Visitor, node Node, path []Node) error { type inspector func(Node, []Node) error func (f inspector) Visit(node Node, path []Node) (Visitor, error) { - if err := f(node, path); err == nil { - return f, nil - } else { + if err := f(node, path); err != nil { return nil, err } + + return f, nil } // Inspect traverses an AST in depth-first order: It starts by calling diff --git a/promql/engine.go b/promql/engine.go index 2bf8705cb..e6e532248 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -614,7 +614,7 @@ func extractFuncFromPath(p []Node) string { return extractFuncFromPath(p[:len(p)-1]) } -func checkForSeriesSetExpansion(expr Expr, ctx context.Context) error { +func checkForSeriesSetExpansion(ctx context.Context, expr Expr) error { switch e := expr.(type) { case *MatrixSelector: if e.series == nil { @@ -966,7 +966,7 @@ func (ev *evaluator) eval(expr Expr) Value { } sel := e.Args[matrixArgIndex].(*MatrixSelector) - if err := checkForSeriesSetExpansion(sel, ev.ctx); err != nil { + if err := checkForSeriesSetExpansion(ev.ctx, sel); err != nil { ev.error(err) } mat := make(Matrix, 0, len(sel.series)) // Output matrix. @@ -1100,7 +1100,7 @@ func (ev *evaluator) eval(expr Expr) Value { }) case *VectorSelector: - if err := checkForSeriesSetExpansion(e, ev.ctx); err != nil { + if err := checkForSeriesSetExpansion(ev.ctx, e); err != nil { ev.error(err) } mat := make(Matrix, 0, len(e.series)) @@ -1175,7 +1175,7 @@ func durationToInt64Millis(d time.Duration) int64 { // vectorSelector evaluates a *VectorSelector expression. func (ev *evaluator) vectorSelector(node *VectorSelector, ts int64) Vector { - if err := checkForSeriesSetExpansion(node, ev.ctx); err != nil { + if err := checkForSeriesSetExpansion(ev.ctx, node); err != nil { ev.error(err) } @@ -1249,7 +1249,7 @@ func putPointSlice(p []Point) { // matrixSelector evaluates a *MatrixSelector expression. func (ev *evaluator) matrixSelector(node *MatrixSelector) Matrix { - if err := checkForSeriesSetExpansion(node, ev.ctx); err != nil { + if err := checkForSeriesSetExpansion(ev.ctx, node); err != nil { ev.error(err) } diff --git a/promql/test.go b/promql/test.go index 4dfd4b245..2bd083495 100644 --- a/promql/test.go +++ b/promql/test.go @@ -606,9 +606,9 @@ func (ll *LazyLoader) parse(input string) error { } ll.loadCmd = cmd return nil - } else { - return raise(i, "invalid command %q", l) } + + return raise(i, "invalid command %q", l) } return errors.New("no \"load\" command found") }