{"record":{"id":"ce82ca3aa25e4bb0","repo":"JuliusBrussee/caveman","slug":"w-empty-name","errorCode":null,"errorMessage":"%w: empty name","messagePattern":"%w: empty name","errorType":"validation","errorClass":"ErrInvalidRule","httpStatus":null,"severity":"error","filePath":"shared/platform/redact/payload.go","lineNumber":579,"sourceCode":"\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.\n\t\t\treturn nil, \"\", fmt.Errorf(\"%w: rule %q matches the empty string\", ErrInvalidRule, r.Name)\n\t\t}\n\t\trepl := r.Replacement\n\t\tif repl == \"\" {\n\t\t\trepl = \"[REDACTED:\" + r.Name + \"]\"\n\t\t}","sourceCodeStart":561,"sourceCodeEnd":597,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/redact/payload.go#L561-L597","documentation":"Every org rule must carry a non-blank Name; compileOrgRules rejects empty or whitespace-only names with ErrInvalidRule. Names identify the rule in the redaction report and in the default [REDACTED:<name>] placeholder, so an unnamed rule is unusable.","triggerScenarios":"Appending a Rule{Name: \"\"} or Name: \"   \" to the rules slice passed to redact.Payload; constructing rules programmatically and forgetting to set Name; decoding rule JSON where the name key is missing.","commonSituations":"Template-generated rule configs with unfilled name fields; rules built in a loop where the name variable was empty; hand-edited YAML/JSON losing the name key.","solutions":["Give every rule a unique, descriptive Name before calling Payload.","Pre-validate with strings.TrimSpace(r.Name) == \"\" and drop/fix offending rules upstream.","Treat errors.Is(err, redact.ErrInvalidRule) as a rule-authoring bug and fail fast with the rule index."],"exampleFix":"// before\nrules = append(rules, redact.Rule{Type: redact.RuleTypeRegex, Pattern: \"sk-[a-z0-9]+\"})\n// after\nrules = append(rules, redact.Rule{Name: \"api-key\", Type: redact.RuleTypeRegex, Pattern: \"sk-[a-z0-9]+\"})","handlingStrategy":"validation","validationCode":"for i, r := range rules {\n    if strings.TrimSpace(r.Name) == \"\" {\n        return fmt.Errorf(\"rule %d has empty name\", i)\n    }\n}","typeGuard":null,"tryCatchPattern":"_, _, err := redact.Payload(body, rules)\nif errors.Is(err, redact.ErrInvalidRule) {\n    // surface the rule-authoring bug to the operator\n}","preventionTips":["Require name as a mandatory field in rule config schemas","Generate names automatically when authors omit them","Add a startup validation pass for all rules"],"tags":["redaction","invalid-rule","validation"],"backgroundTag":"empty-required-field","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"}