cilium/cilium · info
expected KeyValueExpr
Error message
expected KeyValueExpr
What it means
filterRelevantConstructors is called for every KeyValueExpr in the AST and returns this sentinel when the node is not a *ast.KeyValueExpr. It is a benign filter signal, not a user-facing failure — the analyzer skips nodes it does not care about while hunting for *Vec constructor initializers.
Source
Thrown at tools/metricslint/pkg/analyzer/analyzer.go:107
}
nestedKV, ok := slice.Elts[0].(*ast.KeyValueExpr)
if !ok {
return 0, fmt.Errorf("unsupported nested varlen array type")
}
nestedSlice, err := getEllipsisRHSExpansion(nestedKV.Value)
if nestedSlice == nil {
return 0, fmt.Errorf("unsupported nested varlen array: %w", err)
}
return len(nestedSlice.Elts), nil
}
func filterRelevantConstructors(node ast.Node) (object, constructor string, argCount int, err error) {
// Look for an initializer with key-value expressions that call another
// function to initialize the field.
kv, ok := node.(*ast.KeyValueExpr)
if !ok {
return "", "", 0, fmt.Errorf("expected KeyValueExpr")
}
key, ok := kv.Key.(*ast.Ident)
if !ok {
return "", "", 0, fmt.Errorf("expected Key as Ident")
}
call, ok := kv.Value.(*ast.CallExpr)
if !ok {
return "", "", 0, fmt.Errorf("expected Value as CallExpr")
}
// Look for a function with at least two args, where the last arg is a
// composite literal (such as a slice). Example:
//
// metric.NewCounterVec(opts, []string{...})
if len(call.Args) < 2 {
return "", "", 0, fmt.Errorf("expected 2+ arguments to constructor")
}
lastArg, ok := call.Args[len(call.Args)-1].(*ast.CompositeLit)View on GitHub (pinned to ac7b90affa)
Solutions
- No action needed — this error is filtered internally and the node is skipped
- If it appears in a 'metricslint bug' report, inspect the flagged initializer and reshape it into a field: constructor(...) form
Defensive patterns
Strategy: type-guard
Type guard
kv, ok := node.(*ast.KeyValueExpr)
if !ok {
return // not an initializer; analyzer will skip
} Prevention
- Initialize metrics with field: constructor(...) composite literal syntax
- Understand these sentinel errors are internal filters, not code defects
When it happens
Trigger: Any AST node reached by the Preorder walk that is not a key-value expression; in practice the walk is already restricted to KeyValueExpr, so this fires only for non-composite-literal key-value contexts (e.g. slice literals' elements that are not KV pairs).
Common situations: Code under analysis containing composite literals without keys, function calls, or other expression nodes inside literals being scanned by metricslint.
Related errors
- unknown identifier
- expected assignment statement
- unexpected RHS expression length
- expected composite literal
- unsupported ellipsis expression
AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31).
Data as JSON: /api/errors/a3196bd2137fbbf4.
Report an issue: GitHub.