{"record":{"id":"61cab46e96ba4f7e","repo":"crowdsecurity/crowdsec","slug":"missing-mandatory-name-field-in-s-s","errorCode":null,"errorMessage":"missing mandatory 'name' field in %s: %s","messagePattern":"missing mandatory 'name' field in (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/botfile.go","lineNumber":59,"sourceCode":"\trdnsRegexes []*regexp.Regexp\n}\n\nfunc compileBotRegex(pattern string) (*regexp.Regexp, error) {\n\treturn regexp.Compile(\"(?i)\" + pattern) // Force case insensitive match\n}\n\nfunc botFileInit(filename string, line string) error {\n\tentry := &botEntry{}\n\n\tdec := json.NewDecoder(strings.NewReader(line))\n\tdec.DisallowUnknownFields()\n\n\tif err := dec.Decode(entry); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse JSON line in %s: %w\", filename, err)\n\t}\n\n\tif entry.Name == \"\" {\n\t\treturn fmt.Errorf(\"missing mandatory 'name' field in %s: %s\", filename, line)\n\t}\n\n\tif len(entry.IPs)+len(entry.Ranges)+len(entry.RDNS) == 0 {\n\t\treturn fmt.Errorf(\"bot entry '%s' in %s has no identity verification (need at least one of ips/ranges/rdns)\", entry.Name, filename)\n\t}\n\n\tvar err error\n\n\tif entry.UserAgent != \"\" {\n\t\tif entry.uaRegex, err = compileBotRegex(entry.UserAgent); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid user_agent regex for bot entry '%s' in %s: %w\", entry.Name, filename, err)\n\t\t}\n\t}\n\n\tfor _, p := range entry.Paths {\n\t\tre, err := compileBotRegex(p)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid path regex '%s' for bot entry '%s' in %s: %w\", p, entry.Name, filename, err)","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/botfile.go#L41-L77","documentation":"After successfully decoding a bot entry line, botFileInit verifies the mandatory 'name' field is present and non-empty. This error is thrown when the JSON parsed fine but 'name' is missing or set to \"\". The name identifies the bot in logs and error messages, so an unnamed entry is rejected at load time.","triggerScenarios":"A JSONL line in a bots data file decodes successfully into botEntry but has no \"name\" key, or has \"name\":\"\". E.g. {\"ips\":[\"1.2.3.4\"]} or {\"name\":\"\",\"ranges\":[\"10.0.0.0/8\"]}.","commonSituations":"Copy-pasting an entry and deleting the name line; a script generating entries where the name variable was empty; renaming the field to \"bot_name\" or \"id\"; whitespace-only name (JSON-valid but empty after trim considerations — actually only exact empty string triggers, whitespace names pass).","solutions":["Add a non-empty \"name\" field to the offending JSONL line (the error message echoes the full line so you can locate it).","Check the field is spelled exactly \"name\" — not \"Name\" (case matters) or \"bot_name\".","If the name is generated by a script, verify the variable is not empty before writing the line.","Remove blank or placeholder entries like {} that were left in the file."],"exampleFix":"// before\n{\"user_agent\":\"BadBot\",\"ips\":[\"1.2.3.4\"]}\n// after\n{\"name\":\"BadBot\",\"user_agent\":\"BadBot\",\"ips\":[\"1.2.3.4\"]}","handlingStrategy":"validation","validationCode":"// check a decoded line has a name before loading\nvar probe struct{ Name string `json:\"name\"` }\n_ = json.Unmarshal([]byte(line), &probe)\nvalid := strings.TrimSpace(probe.Name) != \"\"","typeGuard":null,"tryCatchPattern":"if err := exprhelpers.FileInit(botFile, \"bots\"); err != nil {\n\tif strings.Contains(err.Error(), \"missing mandatory 'name'\") {\n\t\tlog.Errorf(\"bot entry without a name: %v\", err) // point maintainer at the echoed line\n\t}\n\treturn err\n}","preventionTips":["Always author entries with name first in the JSON object.","Template scripts should fail on empty name variables before writing the line.","CI-validate data files by unmarshalling and checking Name != \"\" for each line.","Never rename the field to Name/bot_name — the schema key is exactly \"name\"."],"tags":["go","json","validation","data-files"],"backgroundTag":"missing-required-config-field","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}