{"record":{"id":"7d4a0040103d9a0f","repo":"JuliusBrussee/caveman","slug":"w-q-rule-q","errorCode":null,"errorMessage":"%w: %q (rule %q)","messagePattern":"%w: %q \\(rule %q\\)","errorType":"validation","errorClass":"ErrRuleUnsupported","httpStatus":null,"severity":"error","filePath":"shared/platform/redact/payload.go","lineNumber":573,"sourceCode":"\tvar sb strings.Builder\n\tfor _, r := range sorted {\n\t\tsb.WriteString(r.Name)\n\t\tsb.WriteByte('\\x1f')\n\t\tsb.WriteString(r.Type)\n\t\tsb.WriteByte('\\x1f')\n\t\tsb.WriteString(r.Pattern)\n\t\tsb.WriteByte('\\x1f')\n\t\tsb.WriteString(r.Replacement)\n\t\tsb.WriteByte('\\x1e')\n\n\t\tswitch r.Type {\n\t\tcase RuleTypeBuiltin:\n\t\t\t// A reference to the unconditional floor. Nothing to run, and\n\t\t\t// nothing it could switch off.\n\t\t\tcontinue\n\t\tcase RuleTypeRegex:\n\t\tcase RuleTypeJSONPath, RuleTypeHeader:\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: %q (rule %q)\", ErrRuleUnsupported, r.Type, r.Name)\n\t\tdefault:\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: %q (rule %q)\", ErrRuleUnsupported, r.Type, r.Name)\n\t\t}\n\n\t\tif strings.TrimSpace(r.Name) == \"\" {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: empty name\", ErrInvalidRule)\n\t\t}\n\t\tif r.Pattern == \"\" {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q has an empty pattern\", ErrInvalidRule, r.Name)\n\t\t}\n\t\tre, err := regexp.Compile(r.Pattern)\n\t\tif err != nil {\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q: %s\", ErrInvalidRule, r.Name, err)\n\t\t}\n\t\tif re.MatchString(\"\") {\n\t\t\t// Such a pattern matches at every position and would replace the\n\t\t\t// whole body with placeholders. Refuse it rather than destroy the\n\t\t\t// capture.","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/redact/payload.go#L555-L591","documentation":"compileOrgRules rejects org-supplied rules whose Type is JSONPath or Header, because Payload only executes plain regex rules against the body. It wraps ErrRuleUnsupported and includes the offending type and rule name so the operator can locate the rule.","triggerScenarios":"Passing a rules slice to redact.Payload containing a Rule with Type: RuleTypeJSONPath or Type: RuleTypeHeader. The error is returned before any matching occurs.","commonSituations":"Porting rule definitions authored for a different redaction engine that supported JSON-path or header-scoped matching; copying rule configs between tools with different capability sets.","solutions":["Replace the unsupported rule with an equivalent regex rule whose pattern targets the same content in the body.","Drop or gate the JSONPath/Header rules before calling Payload, filtering with r.Type == redact.RuleTypeRegex.","Handle errors.Is(err, redact.ErrRuleUnsupported) at call time and log which rule name/type was refused."],"exampleFix":"// before\nrules := []redact.Rule{{Name: \"auth\", Type: redact.RuleTypeHeader, Pattern: \"Bearer\"}}\nout, _, err := redact.Payload(body, rules)\n// after\nrules := []redact.Rule{{Name: \"auth\", Type: redact.RuleTypeRegex, Pattern: \"Bearer\\\\s+[A-Za-z0-9._-]+\"}}\nout, _, err := redact.Payload(body, rules)","handlingStrategy":"validation","validationCode":"for i, r := range rules {\n    if r.Type == redact.RuleTypeJSONPath || r.Type == redact.RuleTypeHeader {\n        return fmt.Errorf(\"rule %d (%q): type %v unsupported by redact.Payload\", i, r.Name, r.Type)\n    }\n}","typeGuard":null,"tryCatchPattern":"out, report, err := redact.Payload(body, rules)\nif errors.Is(err, redact.ErrRuleUnsupported) {\n    // drop or translate the offending rule, then retry\n}","preventionTips":["Only author RuleTypeRegex rules for Payload","Translate JSONPath/Header rules to regex equivalents at config load","Filter unsupported types once at startup, not per-request"],"tags":["redaction","unsupported-rule","validation"],"backgroundTag":"unsupported-enum-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}