rancher/rancher · error
failed to parse jsonpath: %w
Error message
failed to parse jsonpath: %w
What it means
parsePaths is the audit package's shared helper that parses a []string of redaction paths with github.com/rancher/jsonpath. It backs additionalRedactions[].paths parsing; a single malformed expression fails the whole list and the AuditPolicy is rejected.
Source
Thrown at pkg/auth/audit/utils.go:91
return compiled, nil
}
func matchesAny(s string, regexes []*regexp.Regexp) bool {
for _, re := range regexes {
if re.MatchString(s) {
return true
}
}
return false
}
func parsePaths(paths []string) ([]*jsonpath.JSONPath, error) {
compiled := make([]*jsonpath.JSONPath, len(paths))
for i, v := range paths {
jp, err := jsonpath.Parse(v)
if err != nil {
return nil, fmt.Errorf("failed to parse jsonpath: %w", err)
}
compiled[i] = jp
}
return compiled, nil
}
func pairMatches(v any, f func(string, any) bool) bool {
switch v := v.(type) {
case map[string]any:
for k, v := range v {
if f(k, v) {
return true
}
if pairMatches(v, f) {
return true
}View on GitHub (pinned to 932558d4e6)
Solutions
- Compile-check every path with jsonpath.Parse before applying
- Standardize on the brace syntax ({.field.subfield})
- Re-apply and confirm the policy loads
Defensive patterns
Strategy: validation
Validate before calling
import jsonpath "github.com/rancher/jsonpath/pkg"
func validatePaths(paths []string) error {
for _, p := range paths {
if _, err := jsonpath.Parse(p); err != nil {
return fmt.Errorf("path %q: %w", p, err)
}
}
return nil
} Prevention
- Use the same jsonpath library version as Rancher when validating
- Add sample-path tests to policy CI
- Keep a library reference for the supported selector syntax
When it happens
Trigger: Any audit redaction configuration whose paths array contains one malformed JSONPath expression (bare path without braces, unclosed brace, invalid selector).
Common situations: Mixed-style paths where some entries use kubectl-style braces and others are bare; hand-edited CRs.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse paths: %w
- failed to create redactor: %w
- failed to compile headers regexes: %w
- failed to compile regex '%s': %w
- failed to compile regex: %w
AI-assisted analysis of rancher/rancher@932558d4e6 (2026-08-16).
Data as JSON: /api/errors/545f1f4f2b5ff969.
Report an issue: GitHub.