crowdsecurity/crowdsec · error
missing mandatory 'type' field in
Error message
missing mandatory 'type' field in %s: %s
What it means
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.
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.
Example fix
// before
{"pattern":"example.com","tag":"tracker"}
// after
{"pattern":"example.com","tag":"tracker","type":"string"} Defensive patterns
Strategy: validation
Validate before calling
for i, line := range lines {
var rec map[string]string
json.Unmarshal([]byte(line), &rec)
if rec["type"] == "" {
return fmt.Errorf("line %d: missing 'type'", i+1)
}
} Prevention
- 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
When it happens
Trigger: Calling FileInit (via fileMapInit) on a filemap line such as {"pattern":"evil.example.com","tag":"malware"} with no "type" key, or "type":"".
Common situations: 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.
Understand the failure class
Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.
Related errors
- bot entry ' ' in has no identity verification (need at…
- missing mandatory 'pattern' field in
- missing mandatory 'tag' field in
- unknown entry type ' ' in (supported: )
- a condition is required
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/45708b0a8c8ab158.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/exprhelpers/filemap.go:60
// fileMapInit parses a single JSON line and appends it to the fileMapEntry for the given filename.
// Three fields are mandatory: "pattern", "tag", and "type" (one of: "equals", "contains", "regex").
func fileMapInit(filename string, line string) error {
var record map[string]string
if err := json.Unmarshal([]byte(line), &record); err != nil {
return fmt.Errorf("failed to parse JSON line in %s: %w", filename, err)
}
if record["pattern"] == "" {
return fmt.Errorf("missing mandatory 'pattern' field in %s: %s", filename, line)
}
if record["tag"] == "" {
return fmt.Errorf("missing mandatory 'tag' field in %s: %s", filename, line)
}
entryType := record["type"]
if entryType == "" {
return fmt.Errorf("missing mandatory 'type' field in %s: %s", filename, line)
}
if !slices.Contains(validMapEntryTypes, entryType) {
return fmt.Errorf("unknown entry type '%s' in %s (supported: %s): %s",
entryType, filename, strings.Join(validMapEntryTypes, ", "), line)
}
if entryType == "regex" {
if _, err := regexp.Compile(record["pattern"]); err != nil {
log.Warningf("invalid regex pattern in %s: %s", filename, err)
}
}
if dataFileMap[filename] == nil {
dataFileMap[filename] = &fileMapEntry{filename: filename}
}
dataFileMap[filename].rows = append(dataFileMap[filename].rows, record)View on GitHub (pinned to 909b515798)