{"record":{"id":"47df83bb901d1da4","repo":"crowdsecurity/crowdsec","slug":"missing-mandatory-pattern-field-in-s-s","errorCode":null,"errorMessage":"missing mandatory 'pattern' field in %s: %s","messagePattern":"missing mandatory 'pattern' field in (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/filemap.go","lineNumber":51,"sourceCode":"\t// Aho-Corasick automaton for \"contains\" entries (O(|haystack|) matching, checked second).\n\tacAutomaton    *aho_corasick.AhoCorasick\n\tacPatternToRow []int // AC pattern index → row index in fileMapEntry.rows\n\n\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 {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/filemap.go#L33-L69","documentation":"fileMapInit parses each line of a filemap data file as a JSON object and requires a 'pattern' key. This error is thrown when a JSON line has an empty or missing 'pattern' field, since the pattern is what the map is keyed on for expression lookups. The filemap cannot be initialized without it.","triggerScenarios":"Calling FileInit (via fileMapInit) on a filemap where a line decodes to valid JSON but lacks the 'pattern' key or has it set to an empty string.","commonSituations":"Hand-edited .txt data files for MapType (e.g. from a hublist or lookup table) where a row was added with only a tag, or where the pattern column was left blank; files generated by scripts that emit partial records.","solutions":["Open the data file named in the error, find the offending line, and add a non-empty \"pattern\" value.","Validate every JSON line in the file with a script (jq -c each line, check .pattern != \"\") before loading it.","Re-download or regenerate the data file from the upstream hub list if it was corrupted by editing or truncation.","Remove blank or malformed lines that only carry whitespace/placeholder content."],"exampleFix":"// before (data file line)\n{\"tag\":\"bad-bot\"}\n// after\n{\"pattern\":\"8.8.8.8\",\"tag\":\"bad-bot\",\"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[\"pattern\"] == \"\" {\n\t\treturn fmt.Errorf(\"line %d: missing 'pattern'\", i+1)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate every data-file line with jq before loading (jq -c 'select(.pattern == \"\" or .pattern == null)')","Keep data files machine-generated from a single source of truth rather than hand-editing","Add filemap schema checks to CI for custom data files"],"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-14T00:17:10.932Z"}