{"record":{"id":"45708b0a8c8ab158","repo":"crowdsecurity/crowdsec","slug":"missing-mandatory-type-field-in-s-s","errorCode":null,"errorMessage":"missing mandatory 'type' field in %s: %s","messagePattern":"missing mandatory 'type' field in (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/filemap.go","lineNumber":60,"sourceCode":"// 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\n\tif dataFileMap[filename] == nil {\n\t\tdataFileMap[filename] = &fileMapEntry{filename: filename}\n\t}\n\n\tdataFileMap[filename].rows = append(dataFileMap[filename].rows, record)","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/filemap.go#L42-L78","documentation":"After validating 'pattern' and 'tag', fileMapInit requires a 'type' field that classifies the entry (used by existsInFileMaps to route lookups). This error is thrown when the JSON line lacks the 'type' key or it is empty.","triggerScenarios":"Calling FileInit (via fileMapInit) on a filemap line such as {\"pattern\":\"evil.example.com\",\"tag\":\"malware\"} with no \"type\" key, or \"type\":\"\".","commonSituations":"Older data-file formats predating the 'type' field that were never migrated; hand-written lookup files where the author only knew about pattern/tag; hub data files copied from an outdated source.","solutions":["Add \"type\" to the offending line with one of the supported values (see validMapEntryTypes, e.g. ip, range, string, regex, url).","Update the data file to the current filemap format per the crowdsec hub data-file documentation.","Validate each line with a script requiring pattern, tag, and type before loading.","Pull the latest version of the data file from the hub if it is maintained upstream."],"exampleFix":"// before\n{\"pattern\":\"example.com\",\"tag\":\"tracker\"}\n// after\n{\"pattern\":\"example.com\",\"tag\":\"tracker\",\"type\":\"string\"}","handlingStrategy":"validation","validationCode":"for i, line := range lines {\n\tvar rec map[string]string\n\tjson.Unmarshal([]byte(line), &rec)\n\tif rec[\"type\"] == \"\" {\n\t\treturn fmt.Errorf(\"line %d: missing 'type'\", i+1)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check data-file format docs for the current crowdsec version after upgrades","Migrate old-format data files explicitly rather than loading them as-is","Keep a canonical template of the filemap line format in your config repo"],"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"}