{"record":{"id":"d3d4b20d3b330430","repo":"crowdsecurity/crowdsec","slug":"missing-mandatory-tag-field-in-s-s","errorCode":null,"errorMessage":"missing mandatory 'tag' field in %s: %s","messagePattern":"missing mandatory 'tag' field in (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/filemap.go","lineNumber":55,"sourceCode":"\t// Pre-compiled regexps for \"regex\" entries (checked last).\n\tregexPatterns []*regexp.Regexp\n\tregexToRow    []int // regex slice index → row index in fileMapEntry.rows\n}\n\n// fileMapInit parses a single JSON line and appends it to the fileMapEntry for the given filename.\n// Three fields are mandatory: \"pattern\", \"tag\", and \"type\" (one of: \"equals\", \"contains\", \"regex\").\nfunc fileMapInit(filename string, line string) error {\n\tvar record map[string]string\n\tif err := json.Unmarshal([]byte(line), &record); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse JSON line in %s: %w\", filename, err)\n\t}\n\n\tif record[\"pattern\"] == \"\" {\n\t\treturn fmt.Errorf(\"missing mandatory 'pattern' field in %s: %s\", filename, line)\n\t}\n\n\tif record[\"tag\"] == \"\" {\n\t\treturn fmt.Errorf(\"missing mandatory 'tag' field in %s: %s\", filename, line)\n\t}\n\n\tentryType := record[\"type\"]\n\tif entryType == \"\" {\n\t\treturn fmt.Errorf(\"missing mandatory 'type' field in %s: %s\", filename, line)\n\t}\n\n\tif !slices.Contains(validMapEntryTypes, entryType) {\n\t\treturn fmt.Errorf(\"unknown entry type '%s' in %s (supported: %s): %s\",\n\t\t\tentryType, filename, strings.Join(validMapEntryTypes, \", \"), line)\n\t}\n\n\tif entryType == \"regex\" {\n\t\tif _, err := regexp.Compile(record[\"pattern\"]); err != nil {\n\t\t\tlog.Warningf(\"invalid regex pattern in %s: %s\", filename, err)\n\t\t}\n\t}\n","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/filemap.go#L37-L73","documentation":"fileMapInit requires each JSON line of a filemap to carry a 'tag'. This error is thrown when the line parses as JSON and has a valid pattern, but the 'tag' field is missing or empty. The tag is mandatory because it is the value returned by map lookups used in expressions.","triggerScenarios":"Calling FileInit (via fileMapInit) on a filemap line like {\"pattern\":\"1.2.3.4\",\"type\":\"ip\"} where 'tag' is absent or \"\".","commonSituations":"Custom lookup tables built by omitting the tag column; converting CSV data to the JSON-lines filemap format and dropping the label column; template data files with placeholder tags left blank.","solutions":["Add a non-empty \"tag\" value to the offending JSON line in the data file.","Regenerate the file from its source, ensuring the tag/label column is included.","Validate the file line-by-line with jq before loading (check .tag exists and is non-empty).","If the entry genuinely has no meaningful label, give it an explicit placeholder tag instead of an empty string."],"exampleFix":"// before\n{\"pattern\":\"10.0.0.5\",\"type\":\"ip\"}\n// after\n{\"pattern\":\"10.0.0.5\",\"tag\":\"internal\",\"type\":\"ip\"}","handlingStrategy":"validation","validationCode":"for i, line := range lines {\n\tvar rec map[string]string\n\tif err := json.Unmarshal([]byte(line), &rec); err != nil { /* skip */ }\n\tif rec[\"tag\"] == \"\" {\n\t\treturn fmt.Errorf(\"line %d: missing 'tag'\", i+1)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Require pattern+tag+type columns when converting CSV sources to filemap JSON lines","Lint data files in CI before deployment","Never leave a tag blank as placeholder — use an explicit label"],"tags":["data-files","validation","crowdsec"],"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"}