crowdsecurity/crowdsec · error

missing mandatory 'name' field in %s: %s

Error message

missing mandatory 'name' field in %s: %s

What it means

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.

Source

Thrown at pkg/exprhelpers/botfile.go:59

	rdnsRegexes []*regexp.Regexp
}

func compileBotRegex(pattern string) (*regexp.Regexp, error) {
	return regexp.Compile("(?i)" + pattern) // Force case insensitive match
}

func botFileInit(filename string, line string) error {
	entry := &botEntry{}

	dec := json.NewDecoder(strings.NewReader(line))
	dec.DisallowUnknownFields()

	if err := dec.Decode(entry); err != nil {
		return fmt.Errorf("failed to parse JSON line in %s: %w", filename, err)
	}

	if entry.Name == "" {
		return fmt.Errorf("missing mandatory 'name' field in %s: %s", filename, line)
	}

	if len(entry.IPs)+len(entry.Ranges)+len(entry.RDNS) == 0 {
		return fmt.Errorf("bot entry '%s' in %s has no identity verification (need at least one of ips/ranges/rdns)", entry.Name, filename)
	}

	var err error

	if entry.UserAgent != "" {
		if entry.uaRegex, err = compileBotRegex(entry.UserAgent); err != nil {
			return fmt.Errorf("invalid user_agent regex for bot entry '%s' in %s: %w", entry.Name, filename, err)
		}
	}

	for _, p := range entry.Paths {
		re, err := compileBotRegex(p)
		if err != nil {
			return fmt.Errorf("invalid path regex '%s' for bot entry '%s' in %s: %w", p, entry.Name, filename, err)

View on GitHub (pinned to 909b515798)

Solutions

  1. Add a non-empty "name" field to the offending JSONL line (the error message echoes the full line so you can locate it).
  2. Check the field is spelled exactly "name" — not "Name" (case matters) or "bot_name".
  3. If the name is generated by a script, verify the variable is not empty before writing the line.
  4. Remove blank or placeholder entries like {} that were left in the file.

Example fix

// before
{"user_agent":"BadBot","ips":["1.2.3.4"]}
// after
{"name":"BadBot","user_agent":"BadBot","ips":["1.2.3.4"]}
Defensive patterns

Strategy: validation

Validate before calling

// check a decoded line has a name before loading
var probe struct{ Name string `json:"name"` }
_ = json.Unmarshal([]byte(line), &probe)
valid := strings.TrimSpace(probe.Name) != ""

Try / catch

if err := exprhelpers.FileInit(botFile, "bots"); err != nil {
	if strings.Contains(err.Error(), "missing mandatory 'name'") {
		log.Errorf("bot entry without a name: %v", err) // point maintainer at the echoed line
	}
	return err
}

Prevention

When it happens

Trigger: 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"]}.

Common situations: 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).

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


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/61cab46e96ba4f7e. Report an issue: GitHub.